visual basic 12 windows form - c#

I am new to using windows form C# in visual basic 12 . In a ASP.NET form, you can right click on a linkbutton or imagelink, click preferences, and enter in a form under postbackurl to go to the that form after clicking the link/image. How is this done using a linklabel in a windows form? I cannot seem to figure this out.

This is the code you're looking for (by example).
Of course form2 is a new separate form. ;)
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.Show();
}
}

Why would you want to do that?
Windows Forms work on a very different way and level opposed to Web based forms.
In web based forms you have a kind of navigation where you go from one to another page. The original page kind of seizes to exist.
In windows forms you will always have a master window (your application) which call's other windows to open.
The closest thing you can achieve is a linkbutton that opens a new Window or you have to use webpages inside the browsercontrol inside your Windows Form window.

Related

Something similar to form2.cs or another page in winforms visual studio

I just started using C# & Visual Studio for creating Windows Forms applications. I want to make another page or form for my application. For example, when someone will click on "show results" button in the form1.cs design, I want it to redirect them to another page or form2 that shows the results. From googling, I have only seen using "new Form2()" in the code and redesigning the whole new form again. Is there no alternative? if not then how big projects handle all these new forms designing and code?
Thanks!
You can refer to the following steps to solve your problem.
First, right-click on your project and choose “Add>New Item”. Create a new Form called dashboard.cs.
Second double-click on the button “login” in Form1 and add the code in Form1.cs:
private void Btnlogin_Click(object sender, EventArgs e)
{
dashboard d = new dashboard();
this.Hide();
d.Show();
}
Finally we can redirect to another page by click the login button.

move parent form when child form moves in c# winforms

ok , i searched but didnt find what i want so far...
i have a main form and another form named RadEditTemplate.. i ShowDialog() the edit form like this :
new RadEditTemplate().ShowDialog();
i made the RadEditTemplate form the same size as the main form and made it center.
i want to lock these forms together so when i move the editform the main form move with it as well.
i have seen this in Winscp app before.
how can i do this ?
In MainForm:
Form RadEditTemplate = new Form();
RadEditTemplate.Move+=On_Move;
RadEditTemplate.ShowDialog();
void On_Move(object sender, EventArgs e)
{
this.Location = new Point(((Form)sender).Location.X, ((Form)sender).Location.Y);
}

C# - How to close current window and get new window

I'm implementing a window form in C#. I want to close current window and open a new window. (Just like File->New function in applications)
This is my code
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Image_Editor IE = new Image_Editor(); //Image_Editor is the name of window
IE.Show();
this.Close();
}
Images of what I want to achieve:
(source: infosight.com)
I want to implement the "new" function as shown in the above link. When executing given code, new window just appeared and both windows close at the same time.
What should I do to solve this?
if you mean that you want to close this windows and open a windows like your current windows use this
Myform frm; //thats name of the class of your form like Form1
frm = new Myform();
frm.Show(); // show the secend one
this.Close(); // and close the first one

Creating windows forms open new form

When you create a new Windows Forms application, what's the easiest way from dropping a button on the page, creating a click event which will open a new form.
My method requires clicking a button which will open up 9 new forms, all together, but I want to be able to position them where I want, I know the code for this, I just can't seem to open up multiple new forms at the same time?
Button -> Click -> Open 9 new forms which must be open at the same time.
To open a new form
MyForm myForm = new MyForm()
myForm.Show();
Where MyForm is a class that inherits from Form (i.e. your designed form)
How you would do this would depend on whether the forms are all the same or not but
For i as integer = 0 to 8
dim frm as new Form1
frm.Show
Next
Using the static method ie: form1.show is not generally a good idea.
Cheers
Solution in C# using System.Windows.Forms
private void Button_Click(object sender, EventArgs e)
{
Form myForm = new Form();
myForm.Show();
}
To open more than 1 form, a loop with each form would be required.
foreach (Form form in formArray)
{
form.Show();
}

C#: Getting a button to display a preset form

I (currently) have two forms, one that needs to call the other. In other words, by clicking a certain button in Form1, Form2 needs to "pop up", like a dialog box. I know I have to get a reference in both forms, but I'm not entirely sure how to do this. What is a decent tutorial/beginner site to learn about GUIs in C#?
You can try this:
protected void Button1_Click(object sender, EventArgs e)
{
Form2 myForm = new Form2();
myForm.ShowDialog();
}
ShowDialog forces the user to close that window before s/he can access the rest of the application.

Categories