how to keep a form on top of another - vb.net

Say I have 3 forms , Form A , Form B , Form C.
I want Form B to be on top of Form A
and Form C to be on top of Form B.
how do I accomplish this ?

When you call ShowDialog pass the form that you want it to be in front of as a parameter to ShowDialog.

Use the Show(owner) overload to get form B on top of A. You'll need to set the size and location in the Load event so you can be sure it is exactly the right size even after scaling. And listen for the LocationChanged event so you can move the bottom form as well. This works well, other than a few interesting minimizing effects on Win7.
private void button1_Click(object sender, EventArgs e) {
var frmB = new Form2();
frmB.StartPosition = FormStartPosition.Manual;
frmB.Load += delegate {
frmB.Location = this.Location;
frmB.Size = this.Size;
};
frmB.LocationChanged += delegate {
this.Location = frmB.Location;
};
frmB.Show(this);
}

Related

Connecting 2 Forms together [duplicate]

How to make the child form follow main form.
for example: open a winform [.net2], winform opens form, form follows the mainform if mainform is moving.
Use the LocationChanged event from the MainForm to always set the location of the ChildForm.
Working example:
Form childForm = new Form();
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
childForm.StartPosition = FormStartPosition.Manual;
childForm.Width = this.Width;
childForm.Height = 96;
childForm.Location = new Point(this.Left, this.Bottom);
childForm.Show();
}
protected override void OnLocationChanged(EventArgs e) {
base.OnLocationChanged(e);
if (childForm != null) {
childForm.Location = new Point(this.Left, this.Bottom);
}
}
Superficially simple answer is just to add handlers for when Mainform is moved or resized and then set childform Location and size accordingly.
However do you say want to stop main form being moved such that childform end up off screen.
Can child form be moved independantly.
What about minimise and maximise?
Might you want other arrangements, nore than one child, left and right, child form above main form...
Be worth writing a layout class, and shoving all this stuff off to it.

How to Disable Effect on Form Open/Close in vb.net?

I'm trying to make a program where there are multiple forms. Now what I would like to accomplish is that, whenever I open another form, the current form will close but I would like to do that without the forms having to vanish with an effect. Is there a way in the properties to do that? I tried changing the DoublBuffered into TRUE but it has no effect (I mean, the effect was still there). Can somebody point me to the right direction please? Thanks in advance. :D
By the way, I'm using:
Form2.Show()
Me.Close()
I haven't tried it out, but you can use the following. Assuming you have 2 Forms(1,2)
private void Form1_Load(Object sender, EventLog e)
{
if((bool)Form1.ActiveForm)
{
Form1.Visible = true;
Form2.Visible = false;
// Rest of your code to display
}
if((bool)Form2.ActiveForm)
{
Form1.Visible = false;
Form2.Visible = true;
// Rest of your code to display
}
}
Use this,
Form1.Opacity = 0
Here are places to add it. First set Form 2 opacity as 0 in visual studio. and then go to the form load and after loading all the things you need put in,
Form2.Opacity = 100
Then before form 1 closing put in,
Me.Opacity = 0
You just need to know where to set to 0 and where to 100. It will work good. But I am not sure why you don't want that effect.

Knowing When a Particular Data-Point is Clicked?

I have a bar graph and I want to allow the user to right click a particular bar, select some operation (add one or anything really) that will affect only that bar. Is this type of thing possible using ZedGraph?
You can add a Mouse Click event to the Form and call FindNearestObject() passing in that mouse point, you'll get back the nearest object. Something like this perhaps:
private void zedGraphControl2_MouseClick(object sender, MouseEventArgs e)
{
object nearestObject;
int index;
this.zedGraphControl2.GraphPane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out nearestObject, out index);
if (nearestObject != null && nearestObject.GetType() == typeof(BarItem))
{
BarItem barItem = (BarItem)nearestObject;
barItem[index].Y += 1;
zedGraphControl2.Invalidate();
}
}

Is there a way to make binding happen in a Silverlight control that is created in code?

I'm wanting to print a UserControl that binds to a view model. I create the control in code because if I don't it prints off the edge of the page. Apparently, there is no way to control the size or scale of a printed UIElement without screwing up the element that is on the Silverlight page. So I create the 'UserControl' with the following code in the PrintPage event of a PrintDocument:
private void OnPrintPage(object sender, PrintPageEventArgs e)
{
PurchaseReceipt purchaseReceipt = new PurchaseReceipt();
purchaseReceipt.DataContext = _receiptData;
purchaseReceipt.Visibility = System.Windows.Visibility.Visible;
purchaseReceipt.Margin = new Thickness(25.0);
purchaseReceipt.Width = e.PrintableArea.Width - 50.0;
e.PageVisual = purchaseReceipt;
}
The problem is that binding doesn't work, or doesn't work in time. Is there a way to force an element to bind?

Handle Click- Events of Dynamically generated buttons..?? VB.NET

HI,
Am on creation of touch screen UI system.And am generating button for selecting products
Under certain category.
--> array of button creating dynamically And placing in TABPAGE when user selects Tab for category.
The button will be created with the name of products, Under the category selected.
{
'the way am creating controls.
mybutton(j) = new button()
mybutton(j).top = 100
}
How can i get the Click event of those buttons-( in the array)....??
You can use the += operator to assign a handler to an event, for example:
myButton.Click += ButtonClick;
and then declare it like this:
public void ButtonClick(object sender, EventArgs e)
{
// ...
}
Alternatively, if the code is short, you may like to specify it right there directly, for example:
myButton.Click += (sender, e) =>
{
// ...
}
The advantage of that latter method is that you can capture outside variables, such as for example the array of buttons and the index of this particular button.
Have a look at this link. http://forums.asp.net/p/1583639/3997438.aspx
Add button into the list and create a event for that.