Design time link

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is it possible in visual studio 2005 at design time to link
a control on Form 1 to another control on Form 2.

Regards

Charles Mifsud
Shireburn Software Ltd.
 
What do you mean by linking them? You want to access data from a control on
one form by a control on another form? You want to change one control and
have it change the other automically? Can you give more information?

Robin S.
 
Hi Robin,

We want to create a control which handles on execute events, text, enabled,
visible and hint properties like actions in Delphi.

Our problem is that we are going to have repetitive actions in different
forms which we want to handle in one central place. We want to have one
central form or one user control with all the actions and their code for the
whole application.

We want to associate these actions with the controls in the different forms.

Regards

Charles Mifsud
Shireburn Software Ltd.
 
Hi Charles,

I am sorry that I couldn't understand your question exactly.

Could you please tell me what you mean by 'link a control on Form1 to
another control on Form2 at design time'?

Only if I understand your question, I could provide you with possible
assistance.

I look forward to your reply.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Charles,

Sorry that I didn't see your latest message when I wrote my first reply.

If you'd like to call a method when you click a button, for instsance, you
could subscribe the Click event of the button and call the method you'd
like in the button's Click event handler.

To subscribe the Click event of a Button, we could double-click the button
on the form in the designer, and the form designer will generate code to
subscribe the Click event automatically as well as the Click event handler
method in the code view.

Alternatively, we could subscribe the Click event by code. The following is
a sample.

VB.NET sample:

AddHandler Button1.Click, AddressOf Button1_Click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
...
End Sub

C# sample:

this.button1.Click +=new EventHandler(button1_Click);
private void button1_Click(object sender, EventArgs e)
{
......
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Linda,

We misunderstood eachother.

We are interested in developing a component for our company where this is
placed on the main form. This control will be controlling the whole
application.

As an example let us say we have 5 forms with a button and a menu.
Form1, Form2, Form3,Form4 and Form5.

We want to create a control like TActionList in Delphi
and create 1 action.

Control.Action1 = ReportName.Preview();

So instead of going in all the forms and writing in the menuitem and the
button click event ReportName.Preview(); we want just to hook this
control.Action1 to all these forms, so when I click the button or menuitem in
any form it would load the report.

So If we have a situation where a user does not have security rights to view
this report in TActionList of Delphi we just write Control.Action1.Enabled =
false; and all the forms will have the Button and MenuItem disabled
automatically.

Thanks again

Charles
 
Hi Charles,

Thank you for your detailed explanation.

NET Windows Forms application programming model doesn't provide such a
control as the TActionList in Delphi. But we could accomplish the similar
function by set the common function as the event handler of all controls
that need to have the same function.

Let's say we have two forms,e.g. Form1 and Form2. Form1 has a Button called
button1 and Form2 has a Button called button2. If we need to call the same
function when we click the button1 on Form1 and click the button2 on Form2,
we could subscribe the Click event of button1 and button2 as follows:

private void Form1_Load(object sender, EventArgs e)
{
this.button1.Click +=new EventHandler(Class1.Method1);
this.button2.Click +=new EventHandler(Class1.Method1);
}
// define the common function in a class
public class Class1
{
public static void Method1(object sender, EventArgs e)
{
MessageBox.Show("calling method1");
}
}

To set the Enabled propery of all the buttons globally as you described, we
could bind the Enabled property of all the buttons to a variable. In this
case, we may add a public property in the above Class1 and bind the public
property to the Enabled property of the buttons. To get the bound buttons
notified when the data source is changed, we need to implement the
INotifyPropertyChanged interface on the Class1.

The following is a sample.

using System.ComponentModel;
class Class1:INotifyPropertyChanged
{
public bool enabled = true;
public bool Enabled
{
get { return enabled; }
set
{
enabled = value;
if (PropertyChanged != null)
PropertyChanged(this, new
PropertyChangedEventArgs("Enabled"));
}
}
public static void Method1(object sender, EventArgs e)
{
MessageBox.Show("calling method1");
}

public event PropertyChangedEventHandler PropertyChanged;

}
private void Form1_Load(object sender, EventArgs e)
{
this.button1.Click +=new EventHandler(Class1.Method1);
this.button2.Click +=new EventHandler(Class1.Method1);

this.button1.DataBindings.Add("Enabled", c, "Enabled");
this.button2.DataBindings.Add("Enabled", c,"Enabled");

}

Then we could set the Enabled property of the object 'c' to false to
disable both of the buttons globally as follows:
c.Enabled = false;

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Charles,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top