Looking for Dynamic Control Solution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MikeY

    #1

    Looking for Dynamic Control Solution

    Hi Everyone,

    I am working in C#, windows forms.My question is this. All my button dynamic
    controls properties are present and accounted for except for the"FlatStyle"
    properties. I can't seem to figure out, if there is a way of using
    polymorphic way (if that is a word) of doing this particular property. A
    sample of my code is as follows:

    DynamicControls .ButtonControl( this,btnSearchB yName, new Point(5, 75), new
    Size(95, 20), "Name",1,"" ); << Calling

    this.btnSearchB yName.FlatStyle = System.Windows. Forms.FlatStyle .Popup;
    <<<Had to manually input this property here

    public static void ButtonControl(C ontrol parent, Control aControl, Point
    Location, Size Size, String strText, int TabIndex, string strName)
    {
    aControl.Locati on = Location;
    aControl.Size = Size;
    aControl.TabInd ex = TabIndex;
    aControl.Text = strText;
    aControl.Name = strName;
    aControl.Cursor = System.Windows. Forms.Cursors.H and;
    aControl.Font = new System.Drawing. Font("Microsoft Sans Serif", 8.25F,
    System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
    ((System.Byte)( 0)));
    aControl.TabSto p = true;
    aControl.Enable d = true;
    parent.Controls .Add(aControl);
    }

    What I would like to do is to add this property with in my ButtonControl
    function instead of manually adding this below each & every call. Is there a
    way of doing this. Also the FlatStyle does not appear in the Intellisense
    after "aControl." If there is a way, perhaps someone could provide a quick
    simple sample.

    Thank you all in advance and have a good weekend.

    MikeY


  • MikeY

    #2
    Re: Looking for Dynamic Control Solution

    Hi GCL

    I've wired the event with my first line, control:

    DynamicControls .ButtonControl( this,btnSearchB yName, new Point(5, 75), new
    Size(95, 20), "Name",1,"" );

    This control/object is being call in/from my frmMain and calls the function
    "ButtonCont rol" with in a seperate .cs called "Dynamic Controls.cs" my
    control does all the work of position (5,75), size(95,20) etc. Thank you for
    your solution. But, (there always is, lol) your solution is presently what I
    am already using, re: (my second line):

    this.btnSearchB yName.FlatStyle = System.Windows. Forms.FlatStyle .Popup;

    This way is working perfectly, but I was looking for more of a polymorphic
    way of doing this instead of everytime that I'm writing an control/event I
    have to write a "FlatStyle" property after it. I was looking for a way of
    adding this to my function "ButtonCont rol" just like "aControl.Font" , but I
    can't seem to find the solution myself. hmmm It seems like I'm always coming
    up with these querky questions while trying to learn C#, lol. Anyhow, thank
    you again GCL. I'll still look for the solution and I'm sure it is one of
    those simple things that I've just overlooked.

    MikeY



    "gcl" <lnguyen59@comc ast.net> wrote in message
    news:0abd01c34d 5a$c14c62f0$a00 1280a@phx.gbl.. .[color=blue]
    > cast it.. For example,
    >
    > ((System.Window s.Forms.Button) (aControl)).Fla tStyle =
    > System.Windows. Forms.FlatStyle .Flat;
    >
    > Now I got a question for you..
    > How are you going to wire the events for these dynamic
    > controls?
    >
    > Thanks..
    >
    >
    >
    >[color=green]
    > >-----Original Message-----
    > >Hi Everyone,
    > >
    > >I am working in C#, windows forms.My question is this.[/color]
    > All my button dynamic[color=green]
    > >controls properties are present and accounted for except[/color]
    > for the"FlatStyle"[color=green]
    > >properties. I can't seem to figure out, if there is a[/color]
    > way of using[color=green]
    > >polymorphic way (if that is a word) of doing this[/color]
    > particular property. A[color=green]
    > >sample of my code is as follows:
    > >
    > >DynamicControl s.ButtonControl (this,btnSearch ByName, new[/color]
    > Point(5, 75), new[color=green]
    > >Size(95, 20), "Name",1,"" ); << Calling
    > >
    > >this.btnSearch ByName.FlatStyl e =[/color]
    > System.Windows. Forms.FlatStyle .Popup;[color=green]
    > ><<<Had to manually input this property here
    > >
    > >public static void ButtonControl(C ontrol parent, Control[/color]
    > aControl, Point[color=green]
    > >Location, Size Size, String strText, int TabIndex,[/color]
    > string strName)[color=green]
    > >{
    > >aControl.Locat ion = Location;
    > >aControl.Siz e = Size;
    > >aControl.TabIn dex = TabIndex;
    > >aControl.Tex t = strText;
    > >aControl.Nam e = strName;
    > >aControl.Curso r = System.Windows. Forms.Cursors.H and;
    > >aControl.Fon t = new System.Drawing. Font("Microsoft Sans[/color]
    > Serif", 8.25F,[color=green]
    > >System.Drawing .FontStyle.Regu lar,[/color]
    > System.Drawing. GraphicsUnit.Po int,[color=green]
    > >((System.Byte) (0)));
    > >aControl.TabSt op = true;
    > >aControl.Enabl ed = true;
    > >parent.Control s.Add(aControl) ;
    > >}
    > >
    > >What I would like to do is to add this property with in[/color]
    > my ButtonControl[color=green]
    > >function instead of manually adding this below each &[/color]
    > every call. Is there a[color=green]
    > >way of doing this. Also the FlatStyle does not appear in[/color]
    > the Intellisense[color=green]
    > >after "aControl." If there is a way, perhaps someone[/color]
    > could provide a quick[color=green]
    > >simple sample.
    > >
    > >Thank you all in advance and have a good weekend.
    > >
    > >MikeY
    > >
    > >
    > >.
    > >[/color][/color]


    Comment

    • gcl

      #3
      Re: Looking for Dynamic Control Solution

      Well,

      in that function you can check what type of control is
      that and check if the control have the FlatStyle
      property and if it does, then your
      can cast it to button control and set its property

      From your message, I still don't see where u wired
      to control's events. I was talking about, like for
      example,
      500 buttons controls, and when the user click
      on one of the control, it will trigger the delegate

      Anyway, I done them in different way..

      Thanks.



      [color=blue]
      >-----Original Message-----
      >Hi GCL
      >
      >I've wired the event with my first line, control:
      >
      >DynamicControl s.ButtonControl (this,btnSearch ByName, new[/color]
      Point(5, 75), new[color=blue]
      >Size(95, 20), "Name",1,"" );
      >
      >This control/object is being call in/from my frmMain and[/color]
      calls the function[color=blue]
      >"ButtonControl " with in a seperate .cs called "Dynamic[/color]
      Controls.cs" my[color=blue]
      >control does all the work of position (5,75), size[/color]
      (95,20) etc. Thank you for[color=blue]
      >your solution. But, (there always is, lol) your solution[/color]
      is presently what I[color=blue]
      >am already using, re: (my second line):
      >
      >this.btnSearch ByName.FlatStyl e =[/color]
      System.Windows. Forms.FlatStyle .Popup;[color=blue]
      >
      >This way is working perfectly, but I was looking for[/color]
      more of a polymorphic[color=blue]
      >way of doing this instead of everytime that I'm writing[/color]
      an control/event I[color=blue]
      >have to write a "FlatStyle" property after it. I was[/color]
      looking for a way of[color=blue]
      >adding this to my function "ButtonCont rol" just[/color]
      like "aControl.Font" , but I[color=blue]
      >can't seem to find the solution myself. hmmm It seems[/color]
      like I'm always coming[color=blue]
      >up with these querky questions while trying to learn C#,[/color]
      lol. Anyhow, thank[color=blue]
      >you again GCL. I'll still look for the solution and I'm[/color]
      sure it is one of[color=blue]
      >those simple things that I've just overlooked.
      >
      >MikeY
      >
      >
      >
      >"gcl" <lnguyen59@comc ast.net> wrote in message
      >news:0abd01c34 d5a$c14c62f0$a0 01280a@phx.gbl. ..[color=green]
      >> cast it.. For example,
      >>
      >> ((System.Window s.Forms.Button) (aControl)).Fla tStyle =
      >> System.Windows. Forms.FlatStyle .Flat;
      >>
      >> Now I got a question for you..
      >> How are you going to wire the events for these dynamic
      >> controls?
      >>
      >> Thanks..
      >>
      >>
      >>
      >>[color=darkred]
      >> >-----Original Message-----
      >> >Hi Everyone,
      >> >
      >> >I am working in C#, windows forms.My question is this.[/color]
      >> All my button dynamic[color=darkred]
      >> >controls properties are present and accounted for[/color][/color][/color]
      except[color=blue][color=green]
      >> for the"FlatStyle"[color=darkred]
      >> >properties. I can't seem to figure out, if there is a[/color]
      >> way of using[color=darkred]
      >> >polymorphic way (if that is a word) of doing this[/color]
      >> particular property. A[color=darkred]
      >> >sample of my code is as follows:
      >> >
      >> >DynamicControl s.ButtonControl (this,btnSearch ByName,[/color][/color][/color]
      new[color=blue][color=green]
      >> Point(5, 75), new[color=darkred]
      >> >Size(95, 20), "Name",1,"" ); << Calling
      >> >
      >> >this.btnSearch ByName.FlatStyl e =[/color]
      >> System.Windows. Forms.FlatStyle .Popup;[color=darkred]
      >> ><<<Had to manually input this property here
      >> >
      >> >public static void ButtonControl(C ontrol parent,[/color][/color][/color]
      Control[color=blue][color=green]
      >> aControl, Point[color=darkred]
      >> >Location, Size Size, String strText, int TabIndex,[/color]
      >> string strName)[color=darkred]
      >> >{
      >> >aControl.Locat ion = Location;
      >> >aControl.Siz e = Size;
      >> >aControl.TabIn dex = TabIndex;
      >> >aControl.Tex t = strText;
      >> >aControl.Nam e = strName;
      >> >aControl.Curso r = System.Windows. Forms.Cursors.H and;
      >> >aControl.Fon t = new System.Drawing. Font("Microsoft[/color][/color][/color]
      Sans[color=blue][color=green]
      >> Serif", 8.25F,[color=darkred]
      >> >System.Drawing .FontStyle.Regu lar,[/color]
      >> System.Drawing. GraphicsUnit.Po int,[color=darkred]
      >> >((System.Byte) (0)));
      >> >aControl.TabSt op = true;
      >> >aControl.Enabl ed = true;
      >> >parent.Control s.Add(aControl) ;
      >> >}
      >> >
      >> >What I would like to do is to add this property with[/color][/color][/color]
      in[color=blue][color=green]
      >> my ButtonControl[color=darkred]
      >> >function instead of manually adding this below each &[/color]
      >> every call. Is there a[color=darkred]
      >> >way of doing this. Also the FlatStyle does not appear[/color][/color][/color]
      in[color=blue][color=green]
      >> the Intellisense[color=darkred]
      >> >after "aControl." If there is a way, perhaps someone[/color]
      >> could provide a quick[color=darkred]
      >> >simple sample.
      >> >
      >> >Thank you all in advance and have a good weekend.
      >> >
      >> >MikeY
      >> >
      >> >
      >> >.
      >> >[/color][/color]
      >
      >
      >.
      >[/color]

      Comment

      • MikeY

        #4
        Re: Looking for Dynamic Control Solution

        Aaaaaaaaah, I've misunderstood you, sorry bro.

        I wire the event like this:
        btnSearchByName .Click += new System.EventHan dler(SearchBoxA rea);

        You can just treat the "btnSearchByNam e" just like anyother button, Label,
        TextBox, Gridbox etc ie txtBoxFName.tex t
        I do enjoy using Dynamic controls, but sometimes like this & especially
        being that I'm still learning the ropes, it can be head scratching, lol.
        Anyhow have a great weekend.

        Hey if you want a small samply on how I approach this please drop me a line.

        MikeY

        "gcl" <lnguyen59@comc ast.net> wrote in message
        news:046101c34d 79$95743b70$a30 1280a@phx.gbl.. .[color=blue]
        > Well,
        >
        > in that function you can check what type of control is
        > that and check if the control have the FlatStyle
        > property and if it does, then your
        > can cast it to button control and set its property
        >
        > From your message, I still don't see where u wired
        > to control's events. I was talking about, like for
        > example,
        > 500 buttons controls, and when the user click
        > on one of the control, it will trigger the delegate
        >
        > Anyway, I done them in different way..
        >
        > Thanks.
        >
        >
        >
        >[color=green]
        > >-----Original Message-----
        > >Hi GCL
        > >
        > >I've wired the event with my first line, control:
        > >
        > >DynamicControl s.ButtonControl (this,btnSearch ByName, new[/color]
        > Point(5, 75), new[color=green]
        > >Size(95, 20), "Name",1,"" );
        > >
        > >This control/object is being call in/from my frmMain and[/color]
        > calls the function[color=green]
        > >"ButtonControl " with in a seperate .cs called "Dynamic[/color]
        > Controls.cs" my[color=green]
        > >control does all the work of position (5,75), size[/color]
        > (95,20) etc. Thank you for[color=green]
        > >your solution. But, (there always is, lol) your solution[/color]
        > is presently what I[color=green]
        > >am already using, re: (my second line):
        > >
        > >this.btnSearch ByName.FlatStyl e =[/color]
        > System.Windows. Forms.FlatStyle .Popup;[color=green]
        > >
        > >This way is working perfectly, but I was looking for[/color]
        > more of a polymorphic[color=green]
        > >way of doing this instead of everytime that I'm writing[/color]
        > an control/event I[color=green]
        > >have to write a "FlatStyle" property after it. I was[/color]
        > looking for a way of[color=green]
        > >adding this to my function "ButtonCont rol" just[/color]
        > like "aControl.Font" , but I[color=green]
        > >can't seem to find the solution myself. hmmm It seems[/color]
        > like I'm always coming[color=green]
        > >up with these querky questions while trying to learn C#,[/color]
        > lol. Anyhow, thank[color=green]
        > >you again GCL. I'll still look for the solution and I'm[/color]
        > sure it is one of[color=green]
        > >those simple things that I've just overlooked.
        > >
        > >MikeY
        > >
        > >
        > >
        > >"gcl" <lnguyen59@comc ast.net> wrote in message
        > >news:0abd01c34 d5a$c14c62f0$a0 01280a@phx.gbl. ..[color=darkred]
        > >> cast it.. For example,
        > >>
        > >> ((System.Window s.Forms.Button) (aControl)).Fla tStyle =
        > >> System.Windows. Forms.FlatStyle .Flat;
        > >>
        > >> Now I got a question for you..
        > >> How are you going to wire the events for these dynamic
        > >> controls?
        > >>
        > >> Thanks..
        > >>
        > >>
        > >>
        > >>
        > >> >-----Original Message-----
        > >> >Hi Everyone,
        > >> >
        > >> >I am working in C#, windows forms.My question is this.
        > >> All my button dynamic
        > >> >controls properties are present and accounted for[/color][/color]
        > except[color=green][color=darkred]
        > >> for the"FlatStyle"
        > >> >properties. I can't seem to figure out, if there is a
        > >> way of using
        > >> >polymorphic way (if that is a word) of doing this
        > >> particular property. A
        > >> >sample of my code is as follows:
        > >> >
        > >> >DynamicControl s.ButtonControl (this,btnSearch ByName,[/color][/color]
        > new[color=green][color=darkred]
        > >> Point(5, 75), new
        > >> >Size(95, 20), "Name",1,"" ); << Calling
        > >> >
        > >> >this.btnSearch ByName.FlatStyl e =
        > >> System.Windows. Forms.FlatStyle .Popup;
        > >> ><<<Had to manually input this property here
        > >> >
        > >> >public static void ButtonControl(C ontrol parent,[/color][/color]
        > Control[color=green][color=darkred]
        > >> aControl, Point
        > >> >Location, Size Size, String strText, int TabIndex,
        > >> string strName)
        > >> >{
        > >> >aControl.Locat ion = Location;
        > >> >aControl.Siz e = Size;
        > >> >aControl.TabIn dex = TabIndex;
        > >> >aControl.Tex t = strText;
        > >> >aControl.Nam e = strName;
        > >> >aControl.Curso r = System.Windows. Forms.Cursors.H and;
        > >> >aControl.Fon t = new System.Drawing. Font("Microsoft[/color][/color]
        > Sans[color=green][color=darkred]
        > >> Serif", 8.25F,
        > >> >System.Drawing .FontStyle.Regu lar,
        > >> System.Drawing. GraphicsUnit.Po int,
        > >> >((System.Byte) (0)));
        > >> >aControl.TabSt op = true;
        > >> >aControl.Enabl ed = true;
        > >> >parent.Control s.Add(aControl) ;
        > >> >}
        > >> >
        > >> >What I would like to do is to add this property with[/color][/color]
        > in[color=green][color=darkred]
        > >> my ButtonControl
        > >> >function instead of manually adding this below each &
        > >> every call. Is there a
        > >> >way of doing this. Also the FlatStyle does not appear[/color][/color]
        > in[color=green][color=darkred]
        > >> the Intellisense
        > >> >after "aControl." If there is a way, perhaps someone
        > >> could provide a quick
        > >> >simple sample.
        > >> >
        > >> >Thank you all in advance and have a good weekend.
        > >> >
        > >> >MikeY
        > >> >
        > >> >
        > >> >.
        > >> >[/color]
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        Working...