Groups | Blog | Home
all groups > c# > april 2005 >

c# : Class Library Help PLz


MikeY
4/26/2005 11:36:45 PM
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:

[quoted text, click to view]

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, "");
}

[quoted text, click to view]

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

Michael C
4/27/2005 12:00:00 AM
What's the problem?

[quoted text, click to view]

Michael C
4/27/2005 12:00:00 AM
[quoted text, click to view]

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

Michael

MikeY
4/27/2005 12:00:00 AM
Doh! Sometimes the easiest things are overlooked Thanks Michael much
appreciated your help.

MikeY
[quoted text, click to view]

MikeY
4/27/2005 10:48:06 AM
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


[quoted text, click to view]

AddThis Social Bookmark Button