Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

Kastro

@Kastro
About
Posts
33
Topics
6
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Blackout and deregulation
    K Kastro

    They are still in "public hands" in the same sense that generation was before any deregulation began. The actual assets are privately owned by utilities, while the price they charge for transmitting power and how much transmission capacity they are required to have is determined in regulatory proceedings. Deregulation in the power industry exists in that there are regional system operators (ISOs) that are government run which determine the wholesale market price (your $/MWh prices) based on supply from utilities and independent power producers (IPPs). Many places also have open retail access, though mostly only for commercial and industrial (C&I) customers, not residential customers. In retail access independent companies can compete against the regulated retail rates (the cts/kWh ones you see on your bill) of utilities, who can also have their own subsidiaries compete against the regulated rate as well. There are really three businesses historically related to electricity: generation, transmission, and distribution (retail sales). Generation has been deregulated first with distribution following. The problem with transmission is that you can't tell the power where to go. For instance, pretend there are two different lines between the same two places owned by two different companies. A deregulated market implies that each owner is free to set their own price to compete in the market. However, because of Kirchoff's law, there is no way to ensure that in real-time the power will use the line that charges the lower price. You can blame it on the electrons for not being bargain hunters :). (If you're wondering why I know this stuff, I work in the industry)

    The Back Room question discussion

  • Blackout and deregulation
    K Kastro

    Pretty much everyone agrees that the transmission system is to blame for the blackout. Deregulation cannot be blamed then, since transmission is 100% regulated everywhere. Deregulation applies only to distribution (retail access, i.e. independent power marketers) and wholesale generation (merchant power plants that sell to utilities). Utilities own the transmission system, but it is wholly regulated by the government. Transmission will likely never be deregulated, as it technologically doesn't make sense (because of Kirchoff's Law).

    The Back Room question discussion

  • Future C# features
    K Kastro

    Somehow providing delegate inheritance. Don't know how it could be done, but I'd like to be able to do something like the following...

    class MadeHappyEventArgs : EventArgs {
    ...
    }

    public delegate void MadeHappyEventHandler : EventHandler (Object sender, MadeHappyEventArgs e);

    class MakeHappyControl : Control {

    private static readonly Object MadeHappyEvent = new Object();
    
    public event MadeHappyEventHandler MadeHappy {
        add { Events.AddHandler(MadeHappyEvent, value); }
        remove { Events.RemoveHandler(MadeHappyEvent, value); }
    }
    
    protected void OnMadeHappy() {
        RaiseEvent(MadeHappyEvent, new MadeHappyArgs());
    }
    
    private void RaiseEvent(Object event, EventArgs args) {
        // The next line is what it would allow
        EventHandler handler = (EventHandler)Events\[event\];
        if (handler != null)
            handler(this, args);
    }
    

    }

    Would be nice... It's a lot cleaner when you don't have to rewrite that RaiseEvent method for every type of EventArgs event.

    The Lounge csharp visual-studio beta-testing question announcement

  • Most Comical Word
    K Kastro

    peewit

    The Lounge com question announcement

  • YAGJ...
    K Kastro

    Ever since Pilger blamed excess cancer rates in Iraq on the presence of depleted uranium I have begun to take any work of his with a grain of salt. I generally respect his work however, though claiming that FOX dominates the American media is quite a stretch.

    The Back Room com sysadmin help

  • Bush press conference highlights government crisis...
    K Kastro

    they are not. not even close. in fact, they're growing stronger. The IMU has been pretty much eliminated as a result of action in Afghanistan. Their numbers are sparse and they haven't made a notable attack since the US entered Afghanistan. Central Asia is much safer as a result. (Just an example of them not being stronger in this instance)

    The Back Room question announcement lounge

  • Some idiot in a public restroom upbraided me for not washing my hands after peeing!
    K Kastro

    I learned that by watching the quality movie "The Real Cancun" (Although the sting seemed fake to me)

    The Back Room question

  • VSIP is Free now???
    K Kastro

    That's how I understand it... I downloaded it already, except my copy of VS.NET 2003 still hasn't come yet so I can't try it out. It'll be nice to be able to put together packages that can be used for editing and compiling in your own language or for editing your own custom file types... I'm planning on creating a package related to a 3D engine I'm building... Hopefully I'll have the ability to edit (with syntax highlight and intellisense) and compile scripts in a custom language as well as provide editors for a number of custom file types (3D models, texture generation, and shader defintion). Anyone writing an article on how to use VSIP to create support for a new language?

    Visual Studio com question

  • Centering a form?!?
    K Kastro

    Your formula is wrong... Try this:

    this.Top = (this.Owner.Height - this.Height) / 2;
    this.Left = (this.Owner.Width - this.Width) / 2;

    C# question

  • Bind a window to the side of the screen
    K Kastro

    You can just set the location and size of your window based on the current screen dimensions and specify it as a topmost window. To make sure maximized windows don't extend under it you can use the Windows API to specify the work area of any monitor. The work area specifies the "portion of the screen not obscured by the system taskbar or by application desktop toolbars." On the primary monitor you will need to make a call to SystemParametersInfo passing SPI_SETWORKAREA and a new rectangle that leaves room for the taskbar and wherever you want to put your window. For a monitor other than the primary one take a look at GetMonitorInfo...

    C# question

  • RSA Question
    K Kastro

    I think the problem is arising because you are using doubles to store your values. The number 123^17 probably can't be stored exactly as a double. You should use a BigInteger class that can hold as many bits as you want for your encryption algorithm. Check out this article for some good info on implementing a BigInteger class: http://www.codeproject.com/csharp/BigInteger.asp[^] Using that class you will get the correct ciphertext (855) with this code:

    BigInteger e = new BigInteger(17);
    BigInteger d = new BigInteger(2753);
    BigInteger p = new BigInteger(61);
    BigInteger q = new BigInteger(53);
    BigInteger n = p * q;

    BigInteger P = new BigInteger(123);
    BigInteger C = P.modPow(e, n);

    C# question csharp algorithms help

  • Get/set method for an array?
    K Kastro

    Such a property is called an indexer. You can read a tutorial on them in the MSDN documentation (under "indexers->tutorial (C#)")The following is an example...

    public class MyArray {

    ...
    
    public Object this\[int index\] {
        get {
            return \_Items\[index\];
        }
        set {
            \_Items\[index\] = value;
        }
    }
    
    private Object\[\] \_Items;
    

    }

    C# question data-structures

  • MessageBoxIcon
    K Kastro

    The icons are not part of the .NET Framework. The internal implementation of MessageBox.Show just calls the Platform SDK function MessageBox, passing a flag value that specifies the icon you want displayed. The icons themselves are stored as resources in user32.dll.

    C# question

  • How to control the number of instances of a application
    K Kastro

    There is an article on Code Project by Detlef Grohs that describes the process for creating a single instance application in VB.NET. You could use the same technique with modifications to achieve what you want. It involves using Mutexes and .NET Remoting. The article is here: http://www.codeproject.com/vb/net/sing_inistan.asp[^] There is also a sample on MSDN called "Real World Applications" that describes a similar technique (using C#). It's located here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/reaworapps1.asp?_r=1[^]

    C# tutorial question

  • How to Create a new Access database using C#?
    K Kastro

    I'm interested in knowing too. The only other technique I know, and have used before, is to embed a blank database into the assembly and write it out to file using a binary stream whenever a new database is needed. I know, its ugly and bad, but it works. Though if you want to be able to create for different Access versions you'd need to embed each one, which is even more ugly and bad. Also, you can use Interop to access ADOX from C#.

    C# csharp database tutorial question

  • visual studio designer
    K Kastro

    I'm doing something similar right now actually... Working on creating a GUI library and engine using DirectX that is designable. You have to implement IComponent in your class (deriving from Component is a quick way to do this) because the DesignerHost (service provided and used by VS.NET) utilizes sites (ISite), which are the basis of components. Then you have to specify an IRootDesigner-implementing class in a DesignerAttribute for you IComponent class. You can try using ComponentDocumentDesigner for that if you don't need any custom designer stuff. Also check out an article/sample named ShapeLibrary that gives a nice easy example of utilizing design-time services in .NET. You can find it here: http://windowsforms.net/articles/shapedesigner.aspx[^] Hope this helps...

    C# question csharp database visual-studio sysadmin

  • Another image problem
    K Kastro

    What was the Exception that you got? If you want to save to TIFF format you need to specify an encoder like so:

    ImageCodecInfo FindEncoder(ImageFormat format) {
    ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
    for (int i = 0; i < encoders.Length; i++)
    if (encoders[i].FormatID == format.Guid)
    return encoders[i];
    return null;
    }

    ...
    image.Save("target.tiff", FindEncoder(ImageFormat.Tiff), null);
    ...

    Actually the example I gave before for saving an index-formatted image probably should have explicity specified the JPEG encoder even though I believe it uses Image.RawFormat which defaults to the JPEG format (at least on my system).

    C# help tutorial question

  • Another image problem
    K Kastro

    The following will open an image, create a Graphics object to use for drawing to it, draw a string, and save it to another file.

    Image image = Image.FromFile("source.jpg");
    Graphics g = Graphics.FromImage(image);
    g.DrawString("Hello World!", new Font("Tahoma", 24), Brushes.Magenta, 10.0f, 10.0f);
    g.Dispose();
    image.Save("target.jpg");

    Note that this will only work for non-indexed image formats. For an indexed format you could just create a new non-indexed Image into which you first draw the loaded Image before writing other stuff on top. Of course when you save the file it won't be in the same format as the original.

    Image image = Image.FromFile("source.gif");
    Bitmap bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);
    Graphics g = Graphics.FromImage(bmp);
    g.DrawImage(image, 0.0f, 0.0f);
    g.DrawString("Hello World!", new Font("Tahoma", 24), Brushes.Magenta, 10.0f, 10.0f);
    g.Dispose();
    bmp.Save("target.jpg");

    C# help tutorial question

  • int.ToString() format problem
    K Kastro

    This should do the trick: String.Format("{0:00} {1:00} {2:00}", 1, 12, 123) Evaluates to: "01 12 123" Check out the MSDN documentation on String.Format for more information: ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemstringclassformattopic1.htm[^]

    C# question csharp help

  • Serialization Question
    K Kastro

    Serialization and deserialization of MyClassCollection (and the instances of MyClass that it holds) will work properly so long as you apply SerializableAttribute to both MyClassCollection and MyClass. If either class is not marked with SerializableAttribute you will receive a SerializationException when you try to call BinaryFormatter.Serialize. The following demonstrates the serialization of your classes:

    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;

    [Serializable()]
    public class MyClass {

    public MyClass(string name) {
    	\_Name = name;
    }
    
    public string Name {
    	get { return \_Name; }
    }
    
    private string \_Name;
    

    }

    [Serializable()]
    class MyClassCollection {

    public MyClassCollection() {
    	\_Items = new MyClass\[4\];
    }
    
    public MyClass this\[int index\] {
    	get { return \_Items\[index\]; }
    	set { \_Items\[index\] = value; }
    }
    
    public override string ToString() {
    	string result = "MyClassCollection {";
    	for (int i = 0; i < \_Items.Length; i++)
    		result += (i != 0 ? ", " : "") + (\_Items\[i\] != null ? \_Items\[i\].Name : "\[null\]");
    	result += "}";
    	return result;
    }
    
    private MyClass\[\] \_Items;
    
    \[STAThread\]
    static void Main(string\[\] args) {
    	BinaryFormatter formatter = new BinaryFormatter();
    	MemoryStream stream = new MemoryStream();
    	// Populate collection
    	MyClassCollection col = new MyClassCollection();
    	col\[0\] = new MyClass("Item #1");
    	col\[2\] = new MyClass("Item #2");
    	Console.WriteLine(col);
    	// Serialize collection and reset stream to beginning
    	formatter.Serialize(stream, col);
    	col = null;
    	stream.Seek(0, SeekOrigin.Begin);
    	// Deserialize collection
    	col = (MyClassCollection)formatter.Deserialize(stream);
    	stream.Close();
    	Console.WriteLine(col);
    	Console.Read();
    }
    

    }

    Output:

    MyClassCollection {Item #1, [null], Item #2, [null]}
    MyClassCollection {Item #1, [null], Item #2, [null]}

    Hope this helps.

    C# question json tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups