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
U

User 260964

@User 260964
About
Posts
31
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Deleting a listbox item
    U User 260964

    In a Listbox, all items are stored in a 'collection'. You can access this collection using myListbox.Items. Use an indexer (e.g. a number which specifies which items you want) to select a specific item to manipulate. For example, myListBox.Items[0] returns the first item, myListBox.Items[1] the second, and myListBox.Items[myListBox.Items.Count - 1] the last item. You can use the myListBox.Items.Remove() and myListBox.Items.RemoveAt() methods to remove an item. Look in the documentation of the ListBox for further info. - Daniël Pelsmaeker

    As I said before: I never repeat myself!

    C# csharp question learning

  • Array iteration using unsafe code
    U User 260964

    I found this code:

    using System;

    class App {
    unsafe static void Main() {

      // Construct an array consisting of 5 Int32 elements 
      Int32\[\] arr = new Int32\[\] { 1, 2, 3, 4, 5 };
    
      // Obtain a pointer to the array's 0th element
      fixed (Int32\* element = &arr\[0\]) {
    
         // Iterate through each element in the array
         // NOTE: The code below has a bug!
         for (Int32 x = 0, l = arr.Length; x <= l; x++) {
            Console.WriteLine(element\[x\]);
         }
      }
    

    }
    }

    I found it here[^], which I found as the first result by googling your words: "fast array iteration C# unsafe". - Daniël Pelsmaeker

    "All e-mail I send starts with a "Hello Colin" and ends with a suitable goodbye. I get some funny looks from people who aren't called Colin, but at least it's polite." -David Wulff

    C# question csharp com data-structures

  • Array of Interfaces
    U User 260964

    You are right about interfaces = new IMyInterface[10];, but if I recall it correctly, the array is set to a size of 10, but contains NO values, not even null. - Daniël Pelsmaeker

    An egoist is someone who doesn't think about me.

    C# tutorial question csharp com data-structures

  • high precision event triggering in c#
    U User 260964

    First, I don't think that you mean miliseconds (ms). 1000 miliseconds are one second, so you are saying that it only triggers every 15 seconds(!). I suppose you mean nanoseconds (or something alike, something small). Second, much work is done 'behind the screen' when you do something in your program. Therefor, I suggest that you use a (for, do, while(true)) loop to get what you want. You might even want to place the loop on a separate thread. For the rest, I think that getting the intervalls lower is just a matter of optimization (i.e. using unsafe code blocks, maybe even P/Invoke to some Windows API). - Daniël Pelsmaeker

    "I will quote you when you say something memorable."

    C# csharp database question

  • Selecting buttons
    U User 260964

    What about using two global variables (or an array, even better), and a counter. Then, when one button is clicked, the reference to the instance is saved in the first position, and when another button is clicked, it is saved in the second. Like this:

    public class MyClass
    {
    // Initialize a new array with a length of two (thus index 0 and 1):
    private Button[] _buttons = new Button[2];
    private int _counter = 0;

    // Handle the events of your buttons.
    public MyClass()
    {
    MyButton1.Click += new EventHandler(Button_Click);
    MyButton2.Click += new EventHandler(Button_Click);
    MyButton3.Click += new EventHandler(Button_Click);
    // Etc...
    }

    private void Button_Click(object sender, EventArgs e)
    {
    // Assign your button to the array,
    _buttons[_counter] = (Button)sender;
    // and increase the counter by 1.
    _counter++;
    }
    }

    Instead of manually assigning the events to your buttons in the class' constructor, you may want to use the Form-designer to do that. Just copy-and-paste the name of the method that handles the event in the field next to 'Click' on the 'Events' tab of the propertygrid of your buttons. Don't forget to reset the counter (_counter = 0) when you're finished, or add a check to see whether _counter > _buttons.Length - 1, then:

    if (_counter > _buttons.Length - 1) _counter = 0;

    C# question help tutorial

  • moving all an app's menus into menus.cs?
    U User 260964

    I solve this problem using #region directives:

    #region Menus
    private MenuItem mnuFile;
    private MenuItem mnuFileNew;
    private MenuItem mnuFileOpen;
    private MenuItem mnuFileLine1; // A separator.
    private MenuItem mnuFileSave;
    private MenuItem mnuFileSaveAs;
    private MenuItem mnuFileLine2; // Another separator.
    private MenuItem mnuFileExit;
    #endregion

    #region Menu events
    #region File
    private void mnuFileNew_Click(object sender, System.EventArgs e)
    {
    }

    private void mnuFileOpen_Click(object sender, System.EventArgs e)
    {
    }

    private void mnuFileSave_Click(object sender, System.EventArgs e)
    {
    }

    private void mnuFileSaveAs_Click(object sender, System.EventArgs e)
    {
    }

    private void mnuFileExit_Click(object sender, System.EventArgs e)
    {
    }
    #endregion
    #endregion

    Since you use Visual Studio, this would hide the menu code, and add more structure to your source file. - Daniël Pelsmaeker

    And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary. -Shog9

    C# visual-studio question

  • Articles on CodeProject
    U User 260964

    Are there any 'Terms of Use' or something for articles that one wants to submit? In other words: would it be alright to submit any article as long as it is about programming in some language that is spoken on CP? - Daniël Pelsmaeker

    The Lounge question

  • Microsoft .NET parser C# error ?
    U User 260964

    If you use:

    if (foo == null)
    {
    System.Data.Foo _Foo = new System.Data.Foo;
    }

    Now _Foo is only available within the { and }. Now, if you could use the short version:

    if (foo == null)
    System.Data.Foo _Foo = new System.Data.Foo;

    ...then where would _Foo be available? In the { and }, which you left out, or in the parent's context (e.g. between the methods { and })? Because of this confusion, it is not possible.

    C# csharp help question

  • AcceptButton &amp; Show()
    U User 260964

    I think that it has to do with the ShowDialog[^] form being modal, and that Show[^] is inherited from Control[^], which only makes the Form visible. When it's modal, it's usually a form in which the user has to give some input, and press Enter to accept (or Esc to cancel). - Daniël Pelsmaeker

    There are 10 kinds of people in the world. Those that understand binary and those that do not.

    C# help question

  • Options dialog
    U User 260964

    I would create a form, then put a TreeView on it. Set it's Dock property to Left. Then create multiple Panel objects with different names (or create them in your form code in an array). Then, when a specific TreeNode is selected (check in the Click event), you show a specific Panel, and hide the others. You may want to set the Panel's Dock property to Full. - Daniël Pelsmaeker

    C# csharp data-structures

  • Question with treeview
    U User 260964

    You are doing it the hard way. ;) There is an easier way to get what you want, by using the TreeView.SelectedNode[^] property. This property returns the currently selected TreeNode, or null if no node is selected. Now you can test whether the returned TreeNode is a subnode. Remember that a root node doesn't have a Parent node, so we test that:

    public bool IsSubnodeSelected()
    {
    TreeNode selected = MyTreeView.SelectedNode;
    if (selected != null)
    {
    if (selected.Parent != null)
    return true;
    }
    return false;
    }

    The above method would return true if a subnode is selected, and false when a rootnode or no node is selected. - Daniël Pelsmaeker

    C# question data-structures xml tutorial

  • interfaces and GUIDS
    U User 260964

    Im my opinion, a good example of the uses of attributes is when it comes to describing properties for the property explorer in Visual Studio.net.

    using System;
    using System.ComponentModel;

    namespace Examples
    {
    public class ExampleControl : UserControl
    {
    private IndentStyle m_eExampleProperty = IndentStyle.Smart;
    [
    Category("Design"),
    Description("Gets/sets an example value."),
    DefaultValue(IndentStyle.Smart),
    Browsable(true)
    ]
    public IndentStyle ExampleProperty
    {
    get
    {
    return m_eExampleProperty;
    }
    set
    {
    m_eExampleProperty = value;
    }
    }
    }
    }

    This would produce this kind of output:

    If you want to try this out, just cut-and-paste the code into a source file, and create an instance of the control on the designer form. - Daniël Pelsmaeker

    Microsoft is to quality software what McDonalds is to gourmet cooking

    C# help question delphi

  • C# Long to C++ Long
    U User 260964

    In Visual Basic 6, Integer equals C#'s short, so I think that this may be the case with C++ too (I don't know C++, you see). Thus, int should do the trick. - Daniël Pelsmaeker

    "To survive it is often necessary to fight, and to fight you have to dirty yourself." - George Orwell

    C# csharp c++ question

  • Scope
    U User 260964

    Philip Fitzsimons wrote: in this version of c# all parts of a class must be in one file. But this doesn't mean that you can't define non-class dependant enums, delegates, etc... somewhere else. And, if you want to split members into several files to make things more organizable, then you might as well take a look at the #region[^] preprocessor directive. In VS.NET and SharpDevelop, you can expand and collapse the code between two #region and #endregion directives. - Daniël Pelsmaeker


    "Let others praise ancient times; I am glad I was born in these." - Ovid (43 BC-AD 17) Roman poet

    C# csharp data-structures tutorial question

  • How can i get i ShowDialog method in UserControl???
    U User 260964

    If you just want to show or hide a UserControl, than you can use one of the following:

    • Call Show[^] to show the control, and Hide[^] to hide it again.
    • Set Visible[^] to true to show the control, and to false to hide it again.

    If you want to do something else, then please clarify it. - Daniël Pelsmaeker


    This is Linux country. On a quiet night, you can hear NT re-boot.

    C# question csharp winforms

  • getting enum integer ?
    U User 260964

    Try this:

    public enum OutputType : int
    {
    None = 0,
    TIFF = 1,
    JPEG = 2,
    BMP = 3
    }
    [...]
    int num = (int)OutputType.JPEG;

    You can also use uint, long, char, ulong, byte, ubyte, decimal, double, float, and maybe even string. But I suggest int, since it doesn't put such a heavy load on the processor. - Daniël Pelsmaeker


    One fool can ask more questions than all the wise men can answer.

    C# question

  • How can i get i ShowDialog method in UserControl???
    U User 260964

    Just like you would do it when not working on an UserControl:

    MainForm frm = new MainForm();
    frm.ShowDialog(this);

    C# question csharp winforms

  • Custom Formborder style
    U User 260964

    You can set FormBorderStyle = FormBorderStyle.None on the form. No border (or titlebar) will then be shown. Now you can override OnPaint and draw it yourself. - Daniël Pelsmaeker


    C# csharp

  • C# & DOS
    U User 260964

    It is impossible to create a -real- DOS application using .NET, but, as said, you can let an application run in a console (some kind of DOS-box). This is just fake Windows without UI. - Daniël Pelsmaeker


    C# csharp asp-net graphics tutorial question

  • c# &amp; pop_up menue
    U User 260964

    What do you mean? A button which pops up a menu when you click it? Or a button which looks just like the start button? If the first: Use the ContextMenu control. If the latter: Under Windows XP you can use UXTheme.dll (and some C# wrapper) to skin your button. [EDIT]Oops. Didn't read you message's subject line. But please clarify anyway.[/EDIT] - Daniël Pelsmaeker


    C# question csharp help
  • Login

  • Don't have an account? Register

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