469,927 Members | 1,795 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Dynamic Buttons

Hi Everyone,

Does anyone know where I can get my hands on a sample with source code of a
simple dynamic button control in C# Windows form. I am looking for a sample
that uses a class library that sets the properties send/passed from the main
windows form. I'm having problems with the class library, the button control
collection and my referencing it ie this.Control.Add(aControl);.

Any and all help is appreciated. Thanks in advance.

MikeY

Nov 17 '05 #1
6 2719
> simple dynamic button control in C# Windows form

What is a simple dynamic button control? What does it do that is "dynamic"?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:EK*********************@news20.bellglobal.com ...
Hi Everyone,

Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am
looking for a sample that uses a class library that sets the properties send/passed from the main windows form. I'm having
problems with the class library, the button control collection and my referencing it ie this.Control.Add(aControl);.

Any and all help is appreciated. Thanks in advance.

MikeY

Nov 17 '05 #2
Hi Dave,

Its where you create your own buttons or button control, instead of dragging
and dropping the premade button from your component panel. Using the buttons
this way we take adantage of polymorphism.

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
simple dynamic button control in C# Windows form


What is a simple dynamic button control? What does it do that is
"dynamic"?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message
news:EK*********************@news20.bellglobal.com ...
Hi Everyone,

Does anyone know where I can get my hands on a sample with source code of
a simple dynamic button control in C# Windows form. I am looking for a
sample that uses a class library that sets the properties send/passed
from the main windows form. I'm having problems with the class library,
the button control collection and my referencing it ie
this.Control.Add(aControl);.

Any and all help is appreciated. Thanks in advance.

MikeY


Nov 17 '05 #3
Ok, so your question is about design-time interoperability with VS.NET and a WinForms Button derived class?

Are you familiar with custom Designers and Editors? What is the particular problem you are having trouble with?

A simple code example of what your trying to do would help people to understand what your after. There's alot of resources out
there, and to determine the most appropriate more information about your issue is required.

Here's a link to get you started:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:s6*****************@news20.bellglobal.com...
Hi Dave,

Its where you create your own buttons or button control, instead of dragging and dropping the premade button from your component
panel. Using the buttons this way we take adantage of polymorphism.

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
simple dynamic button control in C# Windows form


What is a simple dynamic button control? What does it do that is "dynamic"?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:EK*********************@news20.bellglobal.com ...
Hi Everyone,

Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I
am looking for a sample that uses a class library that sets the properties send/passed from the main windows form. I'm having
problems with the class library, the button control collection and my referencing it ie this.Control.Add(aControl);.

Any and all help is appreciated. Thanks in advance.

MikeY



Nov 17 '05 #4
Hi Dave,

Yes I think that's my question. My problem does lay within design-time. I am
not familiar with Designers or Editors. My source code follows then I'll
detail the problem.
********************
formalin.cs<< Calling form
using System;
using System.Drawing;
using System.Collections;
using System.Component.Model;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace Test
{
public frmMain()
{
InitializeComponent( );
AddControl(new Button( ), new Point(5,5), new Size(75,75), "ButtonName",
0, "");
}
}
********************

ButtonTest.cs<<

using System;

namespace Test
{
public void AddControl(Control aControl, Point Location, Size Size, String
strText, int TabIndex, string strName);
{
aControl.Location = Location;
aControl..Size = Size;
aControl.Text = strText;
aControl.TabIndex = TabIndex;
aControl.Name = strName;
this.Controls.Add(aControl);
}
}

********************

When I put the "AddControl" function within the "frmMain.Test Class" I
recieve no problems at all. When build a Class Library and put the function
in there (for better OOPS) I get the following error: "Test.AddControl" does
not contain a definition for Controls. Hmm

I will look at the link you have provided. If you can think or suggest a
solution I would be much appreciated.

Thanks Dave,

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:eT**************@tk2msftngp13.phx.gbl... Ok, so your question is about design-time interoperability with VS.NET and
a WinForms Button derived class?

Are you familiar with custom Designers and Editors? What is the
particular problem you are having trouble with?

A simple code example of what your trying to do would help people to
understand what your after. There's alot of resources out there, and to
determine the most appropriate more information about your issue is
required.

Here's a link to get you started:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message
news:s6*****************@news20.bellglobal.com...
Hi Dave,

Its where you create your own buttons or button control, instead of
dragging and dropping the premade button from your component panel. Using
the buttons this way we take adantage of polymorphism.

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
simple dynamic button control in C# Windows form

What is a simple dynamic button control? What does it do that is
"dynamic"?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message
news:EK*********************@news20.bellglobal.com ...
Hi Everyone,

Does anyone know where I can get my hands on a sample with source code
of a simple dynamic button control in C# Windows form. I am looking for
a sample that uses a class library that sets the properties send/passed
from the main windows form. I'm having problems with the class library,
the button control collection and my referencing it ie
this.Control.Add(aControl);.

Any and all help is appreciated. Thanks in advance.

MikeY




Nov 17 '05 #5
In C#, and for all I know every other managed language, you must create a class to hold methods. In other words, change your
library code to the following:

namespace Test
{
public class WinFormsCommon
{
// Notice the use of the "static" keyword which makes this method
// accesible without requiring an instance of "WinFormsCommon".
public static void AddControl(Form form, Control aControl, Point Location, Size Size, String
strText, int TabIndex, string strName)
{
// Todo: implemenation

// form has been passed in to this method as a parameter
// because you need a reference to the ControlCollection that "aControl"
// will be added to:
form.Controls.Add(aControl);
}

// This is a private constructor. It is declared to prevent instances of
// "WinFormsCommon" from being created.
private WinFormsCommon() { }
}
}

Note, in 2.0 you can declare static classes, which act the same as VB "modules".

Consume the code above in main:

public frmMain()
{
InitializeComponent( );

// Initialize and add a control to the form:
// (Notice the use of the "this" keyword, which passes an instance of the form
// that has a ControlCollection to add the "new Button()" to.)
WinFormsCommon.AddControl(this, new Button( ), new Point(5,5),
new Size(75,75), "ButtonName", 0, "");
}

When build a Class Library and put the function in there (for better OOPS)
This is not OOP. It definately is not Polymorphism. Instead, it's using a method of a static library. This is no different than
in languages that are not OO.

C# syntax and grammar reference on MSDN:

http://msdn.microsoft.com/library/?u...asp?frame=true

Polymorphism intro:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:Bx*******************@news20.bellglobal.com.. . Hi Dave,

Yes I think that's my question. My problem does lay within design-time. I am not familiar with Designers or Editors. My source
code follows then I'll detail the problem.
********************
formalin.cs<< Calling form
using System;
using System.Drawing;
using System.Collections;
using System.Component.Model;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace Test
{
public frmMain()
{
InitializeComponent( );
AddControl(new Button( ), new Point(5,5), new Size(75,75), "ButtonName", 0, "");
}
}
********************

ButtonTest.cs<<


using System;

namespace Test
{
public void AddControl(Control aControl, Point Location, Size Size, String strText, int TabIndex, string strName);
{
aControl.Location = Location;
aControl..Size = Size;
aControl.Text = strText;
aControl.TabIndex = TabIndex;
aControl.Name = strName;
this.Controls.Add(aControl);
}
}

********************

When I put the "AddControl" function within the "frmMain.Test Class" I recieve no problems at all. When build a Class Library and
put the function in there (for better OOPS) I get the following error: "Test.AddControl" does not contain a definition for
Controls. Hmm

I will look at the link you have provided. If you can think or suggest a solution I would be much appreciated.

Thanks Dave,

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:eT**************@tk2msftngp13.phx.gbl...
Ok, so your question is about design-time interoperability with VS.NET and a WinForms Button derived class?

Are you familiar with custom Designers and Editors? What is the particular problem you are having trouble with?

A simple code example of what your trying to do would help people to understand what your after. There's alot of resources out
there, and to determine the most appropriate more information about your issue is required.

Here's a link to get you started:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:s6*****************@news20.bellglobal.com...
Hi Dave,

Its where you create your own buttons or button control, instead of dragging and dropping the premade button from your component
panel. Using the buttons this way we take adantage of polymorphism.

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
> simple dynamic button control in C# Windows form

What is a simple dynamic button control? What does it do that is "dynamic"?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message news:EK*********************@news20.bellglobal.com ...
> Hi Everyone,
>
> Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form.
> I am looking for a sample that uses a class library that sets the properties send/passed from the main windows form. I'm
> having problems with the class library, the button control collection and my referencing it ie this.Control.Add(aControl);.
>
> Any and all help is appreciated. Thanks in advance.
>
> MikeY
>
>
>



Nov 17 '05 #6
Thank you very much Dave for the solution, and for watching this post. The
solution works and seems to sold my problem. Thank you also for the links
looks like I have some reading ahead, lol.

Much Appreciated,

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:ek****************@TK2MSFTNGP14.phx.gbl...
In C#, and for all I know every other managed language, you must create a
class to hold methods. In other words, change your library code to the
following:

namespace Test
{
public class WinFormsCommon
{
// Notice the use of the "static" keyword which makes this method
// accesible without requiring an instance of "WinFormsCommon".
public static void AddControl(Form form, Control aControl, Point
Location, Size Size, String
strText, int TabIndex, string strName)
{
// Todo: implemenation

// form has been passed in to this method as a parameter
// because you need a reference to the ControlCollection that
"aControl"
// will be added to:
form.Controls.Add(aControl);
}

// This is a private constructor. It is declared to prevent
instances of
// "WinFormsCommon" from being created.
private WinFormsCommon() { }
}
}

Note, in 2.0 you can declare static classes, which act the same as VB
"modules".

Consume the code above in main:

public frmMain()
{
InitializeComponent( );

// Initialize and add a control to the form:
// (Notice the use of the "this" keyword, which passes an instance of
the form
// that has a ControlCollection to add the "new Button()" to.)
WinFormsCommon.AddControl(this, new Button( ), new Point(5,5),
new Size(75,75), "ButtonName", 0, "");
}

When build a Class Library and put the function in there (for better
OOPS)


This is not OOP. It definately is not Polymorphism. Instead, it's using
a method of a static library. This is no different than in languages that
are not OO.

C# syntax and grammar reference on MSDN:

http://msdn.microsoft.com/library/?u...asp?frame=true

Polymorphism intro:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message
news:Bx*******************@news20.bellglobal.com.. .
Hi Dave,

Yes I think that's my question. My problem does lay within design-time. I
am not familiar with Designers or Editors. My source code follows then
I'll detail the problem.
********************
formalin.cs<< Calling form


using System;
using System.Drawing;
using System.Collections;
using System.Component.Model;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace Test
{
public frmMain()
{
InitializeComponent( );
AddControl(new Button( ), new Point(5,5), new Size(75,75),
"ButtonName", 0, "");
}
}
********************

ButtonTest.cs<<


using System;

namespace Test
{
public void AddControl(Control aControl, Point Location, Size Size,
String strText, int TabIndex, string strName);
{
aControl.Location = Location;
aControl..Size = Size;
aControl.Text = strText;
aControl.TabIndex = TabIndex;
aControl.Name = strName;
this.Controls.Add(aControl);
}
}

********************

When I put the "AddControl" function within the "frmMain.Test Class" I
recieve no problems at all. When build a Class Library and put the
function in there (for better OOPS) I get the following error:
"Test.AddControl" does not contain a definition for Controls. Hmm

I will look at the link you have provided. If you can think or suggest a
solution I would be much appreciated.

Thanks Dave,

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:eT**************@tk2msftngp13.phx.gbl...
Ok, so your question is about design-time interoperability with VS.NET
and a WinForms Button derived class?

Are you familiar with custom Designers and Editors? What is the
particular problem you are having trouble with?

A simple code example of what your trying to do would help people to
understand what your after. There's alot of resources out there, and
to determine the most appropriate more information about your issue is
required.

Here's a link to get you started:

http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"MikeY" <mi*******@yaho.com> wrote in message
news:s6*****************@news20.bellglobal.com...
Hi Dave,

Its where you create your own buttons or button control, instead of
dragging and dropping the premade button from your component panel.
Using the buttons this way we take adantage of polymorphism.

MikeY

"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
>> simple dynamic button control in C# Windows form
>
> What is a simple dynamic button control? What does it do that is
> "dynamic"?
>
> --
> Dave Sexton
> dave@www..jwaonline..com
> -----------------------------------------------------------------------
> "MikeY" <mi*******@yaho.com> wrote in message
> news:EK*********************@news20.bellglobal.com ...
>> Hi Everyone,
>>
>> Does anyone know where I can get my hands on a sample with source
>> code of a simple dynamic button control in C# Windows form. I am
>> looking for a sample that uses a class library that sets the
>> properties send/passed from the main windows form. I'm having
>> problems with the class library, the button control collection and my
>> referencing it ie this.Control.Add(aControl);.
>>
>> Any and all help is appreciated. Thanks in advance.
>>
>> MikeY
>>
>>
>>
>
>



Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by brian | last post: by
1 post views Thread by andrei | last post: by
3 posts views Thread by WebBuilder451 | last post: by
3 posts views Thread by NateDawg | last post: by
2 posts views Thread by WolfyUK | last post: by
13 posts views Thread by rn5a | last post: by
5 posts views Thread by Gui | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.