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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
A

AussieLew

@AussieLew
About
Posts
27
Topics
11
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • ListBox control - Freezing one or more rows at top?
    A AussieLew

    I have a Windows Forms ListBox object showing items that originate in a dictionary. To apply different coloring etc to some of the entries I have set dropDownListBox.DrawMode = DrawMode.OwnerDrawFixed and handling the listbox DrawItem and MeasureItem events. The different colored items are basically additional choices or items I add or remove depending on other factors. These are commands if you like eg. "Advanced Filter", "Remove This Filter" etc and always appear at the top of the listbox items, and are highlighted to separate them from the normal data values. When I show the listbox I set the dropDownListBox.SelectedItem to the previously selected item which may be well down the list. I would like to be able to "freeze" the required top row(s) or commands eg "Advanced Filter", so that as I scroll down, or the listbox shows with the previously selected item, the required rows are always visible. This would save scrolling back right back to the start to select "Advanced Filter". Not having much joy so far, can anyone assist? Thanks AussieLew DrawItem and MeasureItem handlers below...

        void dropDownListBox\_DrawItem(object sender, DrawItemEventArgs e)
            {
            Brush myBrush = Brushes.Green;
            Brush backBrush = Brushes.Red; // This color not used
           
            // string to draw
            string listString = dropDownListBox.Items\[e.Index\].ToString();
    
            // paint the list background
            e.DrawBackground();
    
            switch (listString)
                {
                case "Advanced Filter...":
                    myBrush = Brushes.DarkGreen;
                    backBrush = Brushes.PaleGreen;
                    e.Graphics.FillRectangle(backBrush, e.Bounds);
                    // check what filter commands are included in the list
                    // draw a separator line below the command if it is the last before the autofilter choices
                    if (filterCommandFlag == 2)
                        {
                        // needed to draw the line at e.Bounds.Bottom-1 otherwise the line was overwritten at times
                        e.Graphics.DrawLine(Pens.Green, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                        }
                    break;
    
                case "Remove This Filter":
                    myBrush = Brushes.DarkGreen;
                    backBrush = Brushes.PaleGreen;
                    e.Graphi
    
    C# database winforms graphics question

  • Why declare an instance of new class as the base type?
    A AussieLew

    I have been working through some code from articles here, altering to suit my needs etc One particular thing puzzles me. Say DgvFilterHost inherits from DgvBaseFilterHost. Why, if a class inherits from a base class, do they declare an instance of the new class as the base type? for example....

    public DgvBaseFilterHost FilterHost {
    get {
    if (mFilterHost == null) {
    // If not provided, use the default FilterHost
    FilterHost = new DgvFilterHost();

    It seems it makes additional public properties created in DgvFilterHost inaccessible without casting. Even then I seem to have trouble accessing additional properties. Curious as to why you would not make FilterHost type DgvFilterHost in this example? Thank in advance AussieLew

    C# tutorial question

  • desable a menustrip item
    A AussieLew

    I had a similar need a few months back. Ended up using events so that the forms are de-coupled etc (Also learnt a lot about events in the process!) Thread is at http://www.codeproject.com/Messages/3535226/Accessing-mdiParent-form-menu-from-mdiChild-form-v.aspx[^] A little bit more work, though as I had multiple mdi child forms that could alter the menuitem state I thought it was a great solution. Cheers AussieLew

    C# question

  • ToolStripDropDown - ToolStripControlHost with ComboBox problem
    A AussieLew

    Using VS 2008. I have a ToolStripDropDown with a ToolStripControlHost containing a ComboBox (plus other controls). I have a handler attached to the ToolStripDropDown Closing event. The ComboBox has 8 items. When the list is dropped down the lower 5 items protrude beneath the ToolStripDropDown and overlay the form beneath. (At this point ToolStripDropDown.AutoClose is set to True.I need it set to this at this point) When any of these lower 5 items are selected in the list, the ToolStripDropDown Closing event is fired with ToolStripDropDownClosingEventArgs of ToolStripDropDownCloseReason.AppClicked. If any of the top 3 items ( the items of the list within the bounds of the ToolStripDropDown )are selected, it works as expected ie. no Closing event. If the Closing event handler is disabled temporarily, any of the 8 items can be selected. I'm guessing that when the portion which is overlaying the form is clicked, the dropdown list disappears and somehow the click is seen on the form? Is this normal behaviour? If so is there a way to work around? Thanks for any help.....

    C# help visual-studio question

  • ToolStripMenuItem.Visible always returns false? (Clarified hopefully)
    A AussieLew

    Thanks again Dave, The documentation for Available actually explains Visible better than the Visible Docs. I thought that it must have been working correctly, (in an odd way). Just couldn't see it in the documentation. Thanks Lew

    C# help question

  • ToolStripMenuItem.Visible always returns false? (Clarified hopefully)
    A AussieLew

    Thanks Dave

    DaveyM69 wrote:

    This is the correct behaviour. As the parent menu item isn't visible, it is impossible for the child to be visible therefore setting the Visible property has no effect.

    The parent menu item is visible. If I get the value of any top level menu item it returns the correct value i.e True if set to Visible = True; Whereas the lower menu levels return False even if set to True. (Even if the parent menu item is Visible) It looks to me like a subitem returns false because it is not visible until the menu drops down from the parent. Is this normal behaviour? Is the system changing the Visibility property temporarily until the menuitem drops down and is visible? (if the Parent is visible and even if subitem.Visibilty = true) Lew

    C# help question

  • Is there a good example of using multiple forms.....
    A AussieLew

    Sounds similar to what I wanted to do. Form2 needed to set a menuitem on Form1. this was done by creating the event in Form2 registering the handler in Form1. Form 2 also needed to know the status of some menuitems in Form1. This was done by creating the event in Form2 with and registering the handler in Form1. This handler sets one of the custom eventargs properties and returns them to Form2. It was a combination of Daves examples. I'm sure DaveyM69 will explain it more succintly! Thread of my question is Here may help.

    C# json tutorial

  • Is there a good example of using multiple forms.....
    A AussieLew

    DaveyM69 wrote:

    then my article[^] for a more complete tutorial

    Had reason to use this recently, a very helpful article from a helpful guy. Thanks again Dave!

    C# json tutorial

  • ToolStripMenuItem.Visible always returns false? (Clarified hopefully)
    A AussieLew

    Matt U. wrote:

    So, if the item is visible and you then do 'item.Visible = false;' does that make it disappear? And how about after 'Visible' is set to 'false'? If you then call 'item.Visible = true;' does the item actually show up again?

    Yes when setting the Visible property in this way the item disappears and appears as you would expect. It just always returns false. Even something like....

    item.Visible = true;
    bool isVisible = item.Visible;

    returns false, despite actually being Visible. Hence the inabilty to Toggle based on it current state. What I have found is that the top level menu items behave as expected, whereas the lower level, or at least mine on the 2nd and 3rd levels don't seem to behave?

    modified on Friday, September 3, 2010 12:59 AM

    C# help question

  • ToolStripMenuItem.Visible always returns false? (Clarified hopefully)
    A AussieLew

    I have just struck this. Using VS2008

    private void button2_Click(object sender, EventArgs e)
    {

        // ToolStripMenuItem.Visible always returns false?
            // This has the effect of not being able to toggle or invert the state to false by
            // assigning its negated value by use of the ! operator.
            // If the initial state is Visible = false the first click will toggle to Visible = true
            // Subsequent clicks do not change the Visible property as Visible always returns false
            // So, no matter the true state it will always set Visible = true rather than the inverse;
            
    
            // always returns false even if set to Visible = True
            bool cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // always returns true
            bool cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}",cond1,cond2));
    
            // try to invert the value of confirmDeletesToolStripMenuItem.Visible 
            this.confirmDeletesToolStripMenuItem.Visible = !this.confirmDeletesToolStripMenuItem.Visible;
    
            // still always returns false
            cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // still always returns true
            cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}", cond1, cond2));
    
            
            }
    

    The confirmDeletesToolStripMenuItem is not the topmost menuitem. If I get the value of any top level menu item it returns the correct value i.e True if set to Visible = True; Whereas the lower menu levels return False even if set to True. I would have thought that the Visible property is a reflection of whether it should be displayed rather than whether it can be seen? I can set the Visible property directly eg this.confirmDeletesToolStripMenuItem.Visible = True; but still returns False. Thanks for any help....

    C# help question

  • PDF based project
    A AussieLew

    I have a project coming up (unpaid) indexing newsletters for a Gardening group I am a member of. The newsletters are in PDF format. As I dabble in c# I thought I may be able to automate the process somewhat. There appears to be a lot of c# pdf stuff out there to generate and manipulate .pdf docs. Based on your experience I'm hoping to shorten the process of finding the right solution. My initial needs are fairly simple.... 1) Open an unprotected pdf document. 2) Browse the document. 2) Double click (or select somehow) different selected words. (this should then highlight every instance of each selected word throughout the document as a visual cue it has been selected already) 3) Generate an index showing A) the selected word and B) the page number(s) I have a lot of documents to process and they will continue to be ongoing so any help would be great.

    C# csharp database help

  • ToolStripMenuItem.Visible always returns false?
    A AussieLew

    I had a thought after my last post. The confirmDeletesToolStripMenuItem is not the topmost menuitem. If I get the value of any top level menu item it returns the correct value i.e True if set to Visible = True; Whereas the lower menu levels return False even if set to True. I would have thought that the Visible property is a reflection of whether it should be displayed rather than whether it can be seen? Getting closer but stranger?

    modified on Saturday, August 28, 2010 3:17 AM

    C# question

  • ToolStripMenuItem.Visible always returns false?
    A AussieLew

    johannesnestler wrote:

    Can you set the Visible-property?

    Yes, I can set the Visible property to either True or False directly. And that works. It is only when trying to toggle it by using the ! operator it always returns True. (Because getting the value of .Visible always returns False) So if I set it either in the property grid or in code, to False. The MenuItem is Not visible as expected. The first toggle using the ! operator then makes it visible, further toggles continue to leave it visible as it just keeps setting it to True. (because this.confirmDeletesToolStripMenuItem.Visible continues to return false!) Without worry about my previous code, to simplify my example, even if I do something like....

    this.confirmDeletesToolStripMenuItem.Visible = true;
    mbox("Visible = " + this.confirmDeletesToolStripMenuItem.Visible.ToString());

    I still get False! ??

    C# question

  • ToolStripMenuItem.Visible always returns false?
    A AussieLew

    I have just struck this. Using VS2008

    private void button2_Click(object sender, EventArgs e)
    {

        // ToolStripMenuItem.Visible always returns false?
            // This has the effect of not being able to toggle or invert the state to false by
            // assigning its negated value by use of the ! operator.
            // If the initial state is Visible = false the first click will toggle to Visible = true
            // Subsequent clicks do not change the Visible property as Visible always returns false
            // So, no matter the true state it will always set Visible = true rather than the inverse;
            
    
            // always returns false even if set to Visible
            bool cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // always returns true
            bool cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}",cond1,cond2));
    
            // try to invert the value of confirmDeletesToolStripMenuItem.Visible 
            this.confirmDeletesToolStripMenuItem.Visible = !this.confirmDeletesToolStripMenuItem.Visible;
    
            // still always returns false
            cond1 = this.confirmDeletesToolStripMenuItem.Visible; 
    
            // still always returns true
            cond2 = !this.confirmDeletesToolStripMenuItem.Visible; 
    
            MessageBox.Show(string.Format("Cond1 = {0} Cond2 = {1}", cond1, cond2));
    
            
            }
    

    Thanks for any clues!

    C# question

  • Accessing mdiParent form menu from mdiChild form via code [solved]
    A AussieLew

    Thanks once again! I will try your option 3 I think. I have spent a lot of time getting one Form right with data validation and save, edit delete actions etc. I have a few forms along similar lines to come yet. My next task was to simplify creation of these additional forms. By having the child form pass the parent form data through events and having the parent form look after some of the actions, like add, edit, delete, save etc this would be some things that would not have to be duplicated in each form. This is starting to get off topic now but I guess for similar forms with different data sources etc I should set up a form with a constructor that takes the parameters I want to change, plus events etc for form interaction, and use that as a basis for all my similar forms. Lew

    C# question help

  • Accessing mdiParent form menu from mdiChild form via code [solved]
    A AussieLew

    Thanks Dave, I can see how using an event is the better way for the child form to cause a change in the parent form. Your article on events etc has helped clarify delegates etc to a great extent. Anything I'm missing I'm sure will "click" soon! The second part of my question regarded getting the state of the ToolStripMenuItem on the MainForm from the child form. So for example, if the MainForm ToolStripMenuItemConfirmDeletes item is Checked or not I can take the appropriate action when deleting a record on the child form. The only way I can see is to have a static variable (say in the startup code Static Class) bool confirmDeletes that is set whenever the MainForm ToolStripMenuItemConfirmDeletes.Checked property changes. This is accessible from all child forms and the MainForm as eg. Program.confirmDeletes Can ( and should ) this be done via an event or is using a Static variable acceptable practice? Lew

    C# question help

  • Accessing mdiParent form menu from mdiChild form via code [solved]
    A AussieLew

    Thanks, there is a lot to absorb here ( for me anyway ) so I will work my way through it. I'm sure I will be wiser when I understand it completely. I have been struggling with fully understanding the concept of delegates, so this will prompt me to get a handle on that first.

    C# question help

  • Accessing mdiParent form menu from mdiChild form via code [solved]
    A AussieLew

    Thanks, the problem with that ( I think ) is that the value of the ToolStripMenuItem could be changed subsequently by another open MdiChild form. One way that I can get half of what I need is to have a public static variable in a static class ( say my starting code ) which I can access from all of my forms. I can then set the value of this to the value of the ToolStripMenuItem.Checked property in the CheckedChanged event handler for the ToolStripMenuItem. I can then check ToolStripMenuItem.Checked for a certain condition from any child form. But.... how can I Set the ToolStripMenuItem.Checked property in code? It may help if I give a better example of what I want to do. In MainForm ( the MdiParent form ) I have a confirmDeletesToolStripMenuItem with CheckOnClick set to True. In any child form, during the delete process, if MainForm confirmDeletesToolStripMenuItem.Checked == True; then they will get a Confirm Deletes Message Box or not if False. In the Confirm Deletes Message Box I will also have a CheckBox option "Do not show again for this session" that if checked will Set the MainForm confirmDeletesToolStripMenuItem.Checked = False;. I guess I can also use Application Settings and set this type of thing in an Options form rather than on a Checked ToolStripMenuItem, however I'm sure there will be other reasons Get/Set the value of the Parent form from Child?

    C# question help

  • Accessing mdiParent form menu from mdiChild form via code [solved]
    A AussieLew

    I have a start up form call MainForm called as follows...

    static void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new MainForm());
    }

    On MainForm I have a MenuStrip with MenuItems and ToolStripMenuItems. Some of these ToolStripMenuItems have a property of CheckOnClick set to True. From MainForm I open another form called f1 based on HormoneTypeForm, as an MDI child...

    private void hormoneTypeToolStripMenuItem_Click(object sender, EventArgs e)
    {
    HormoneTypeForm f1 = new HormoneTypeForm();
    f1.MdiParent = this;
    hormoneTypeToolStripMenuItem.Enabled = false;
    f1.Show();
    }

    My question is - From form f1 how do I get ( or set ) the Checked value of some of the ToolStripMenuItems on the MainForm menu? What I want to do in form f1 is take actions conditional on the Checked value of some ToolStripMenuItems on the main form MainForm (MdiParent). I cannot find anyway to reference the MainForm ToolStripMenuItems properties from form f1. I'm sure it simple but.....? Thanks for any help.

    modified on Saturday, July 31, 2010 4:51 AM

    C# question help

  • Accessing mdiParent form menu from mdiChild form via code
    A AussieLew

    I have main start up form call MainForm called as follows...

    static void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new MainForm());
    }

    On MainForm I have a MenuStrip with MenuItems and ToolStripMenuItems. Some of these ToolStripMenuItems have a property of CheckOnClick set to True. From MainForm I open another form called F1 based on HormoneTypeForm, as an MDI child...

    private void hormoneTypeToolStripMenuItem_Click(object sender, EventArgs e)
    {
    HormoneTypeForm f1 = new HormoneTypeForm();
    f1.MdiParent = this;
    hormoneTypeToolStripMenuItem.Enabled = false;
    f1.Show();
    }

    My question is - from form F1 I want to be able to get and set the Checked value of some of the ToolStripMenuItems on the MainForm menu. I cannot find anyway to reference the ToolStripMenuItems on MainForm from F1. I'm sure it simple but.....? Thanks for any help.

    Database question 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