Class Library Help PLz

M

MikeY

Hi everyone,

I am trying to learn how to use dynamic controls with/by calling a class
library that contains the properties that will set them. Send/called from
the main form. I am using windows forms, C#. The two codes for the two forms
are as follows:

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

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

using System;

namespace Test
{
private 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);
}
}

Any and all help is appreciated.

MikeY
 
M

Michael C

What's the problem?

MikeY said:
Hi everyone,

I am trying to learn how to use dynamic controls with/by calling a class
library that contains the properties that will set them. Send/called from
the main form. I am using windows forms, C#. The two codes for the two
forms are as follows:


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

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


using System;

namespace Test
{
private 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);
}
}

Any and all help is appreciated.

MikeY
 
M

MikeY

Hi Michael,

The problem lies in that when I separate the AddControl function onto a
separate class (page). I send my properties to this, and when I try to build
I get an error because of the "this.Controls.Add(aControl);" The error is
this: "Test.ButtonTest" does not contain a definition for Controls. Hmmm

Also the AddControl function is actually public, not private. I did a
type-o.

Any and all help is appreciated.

MikeY
 
M

Michael C

MikeY said:
Hi Michael,

The problem lies in that when I separate the AddControl function onto a
separate class (page). I send my properties to this, and when I try to
build I get an error because of the "this.Controls.Add(aControl);" The
error is this: "Test.ButtonTest" does not contain a definition for
Controls. Hmmm

Also the AddControl function is actually public, not private. I did a
type-o.

Any and all help is appreciated.

You have to pass a reference to the page into your function.

Michael
 
M

MikeY

Doh! Sometimes the easiest things are overlooked Thanks Michael much
appreciated your help.

MikeY
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top