User Control

L

Lou

I created a user control using VS2008 that has one button and one text box.
Pressing the button displays a message box. the text box control has no
text.

I registered the control it for COM then instantiated it in VB6. The control
shows itself fine.
When the user hits the button the message box appears, That's great.
But the question is how do I expose the text box in the user control so
the user from the VB6 app can add text to it?

-Lou
 
Z

z.sessions

I created a user control using VS2008 that has one button and one text box.
Pressing the button displays a message box. the text box control has no
text.

I registered the control it for COM then instantiated it in VB6. The control
shows itself fine.
When the user hits the button the message box appears, That's great.
But the question is how do I expose the text box in the user control so
the user from the VB6 app can add text to it?

Use a property in the usercontrol class.
 
J

Jeff Johnson

I created a user control using VS2008 that has one button and one text box.
Pressing the button displays a message box. the text box control has no
text.

I registered the control it for COM then instantiated it in VB6. The
control shows itself fine.
When the user hits the button the message box appears, That's great.
But the question is how do I expose the text box in the user control so
the user from the VB6 app can add text to it?

Don't expose the text box directly. Make a property on the UserControl and
then when the user writes to this property, set the text of the text box.
Conversely, in the getter, simply return the text from the text box.

This kind of thing is referred to as "delegation."
 
L

Lou

I have tried that and the text box doesn't update when the control is hosted
by a VB6 app.
It does update when hosted by another C# Windows App?
public string TextBoxData

{

get { return this.txtData.Text; }

set

{

this.txtData.Text = value;

this.txtData.Refresh();

}

}
 
L

Lou

This code executes and a message box with the new data dispalys
but no data is drawn into the textbox on the user control?

private void txtData_TextChanged(object sender, EventArgs e)

{

TextBox tb;

tb = (TextBox)sender;

MessageBox.Show(tb.Text);

}

I created a user control using VS2008 that has one button and one text
box.
Pressing the button displays a message box. the text box control has no
text.

I registered the control it for COM then instantiated it in VB6. The
control
shows itself fine.
When the user hits the button the message box appears, That's great.
But the question is how do I expose the text box in the user control so
the user from the VB6 app can add text to it?

Use a property in the usercontrol class.
 
Z

z.sessions

This code executes and a message box with the new data dispalys
but no data is drawn into the textbox on the user control?

private void txtData_TextChanged(object sender, EventArgs e)

{

TextBox tb;

tb = (TextBox)sender;

MessageBox.Show(tb.Text);

}

This may be a long shot, but try doing an:

Application.DoEvents();

after setting the textbox's Text property.
 
L

Lou

That did not work.
It seems very simple but maybe its the windows message system doesn't work
when VB6 hosts a .NET User control.
Anybody know enough to explain?

Code from below pressing Command2 the mesage box shows up but the text box
never displays any text in it.
Very simple idea but can't get it to work.

-louie

code from C#
public string TextBoxData

{

get { return this.txtData.Text; }

set

{



private void button1_Click(object sender, EventArgs e)

{

MessageBox.Show("Hello from C# User Control", "Test", MessageBoxButtons.OK);

}

MessageBox.Show("I'm Called: " + value.ToString());

m_szTextboxData = value;

label2.Text = value;

this.txtData.Text = value.ToString();

txtData.Invalidate();

Application.DoEvents();


}

}



code from VB6

Private csharp As New CSharpUserControl.UserControl1

Private Sub Form_Load()
Me.Controls.Add csharp, "dotnet"
Me.Controls("dotnet").Visible = True
End Sub



Private Sub Command2_Click()
csharp.TextBoxData = CStr(Now)
End Sub
 

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