473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2891
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: brian | last post by:
'visual studio 2002 pro 1.0 framwork' I am creating dynamic Link buttons on my intranet site and assigning a click_event to them. A user clicks a link and I call the method to recreate the...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
2
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
5
by: Gui | last post by:
Hi, I'm working in C# .net 2005 with Ajax. I have a page that loads dynamic user controls depending on the scenario. In those user controls, I create dynamic linkbuttons. The user controls are...
2
by: remya1000 | last post by:
hai i'm using Vb.net. i'm creating 64 dynamic created buttons of 8 rows and 8 columns. And i have 1 Go button, 1 textbox. those were created dynamically. if i enter one number inside textbox and...
2
Frinavale
by: Frinavale | last post by:
I've created a ASP.NET control that displays a "book" of schedules. It dynamically displays scheduling times and allows the user to page through the schedules. It also lets the user edit the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.