|
Possibly like so:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Form2 f = new Form2();
f.Show();
}
public static void C1(object sender, EventArgs e)
{
MessageBox.Show("C1");
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
button1.Click += new EventHandler(Form1.C1);
}
}
|
|
|
|
|
Joost thanks for this solution.
You should reply in the forum, so other people can learn or perticipate. If you instantiate your forms with the button from the Map editor you can pass a reference to the map editor and then you do not need a static method. Like the following (Form1 is the map editor and Form2 is a "form with a button"):
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Form2 f = new Form2(foo);
f.Show();
}
public void foo(object sender, EventArgs e)
{
MessageBox.Show("foo");
this.Text = "I was foo-ed";
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(EventHandler h)
{
InitializeComponent();
this.button1.Click += h;
}
}
Another approach is the following:
public partial class Form1 : Form
{
public static EventHandler fooHandler;
public Form1()
{
InitializeComponent();
fooHandler = foo;
Form2 f = new Form2();
f.Show();
}
public void foo(object sender, EventArgs e)
{
MessageBox.Show("foo");
this.Text = "I was foo-ed";
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.button1.Click += Form1.fooHandler;
}
}
it works lik this
|
|
|
|
|
I also meet another problem.
With passing values between forms.
This is what Microsoft help says.
form 1
private Form2 otherForm;
private void GetOtherFormTextBox()
{
textBox1.Text = otherForm.TextBox1.Text;
}
and form 2
public TextBox TextBox1
{
get
{
return textBox1;
}
}
But when i do this i get any value at all?
my code know in til map editor?
public void CurrentTileChange(object sender, EventArgs e)
{
if (tileset != null)
{
int index = (int)form2.nudCurrentTile.Value;
FillPictureBox(index);
tileDisplay1.Invalidate();
}
what do i have to change to make it right?
|
|
|
|
|
You could pass data using your own eventhandler!
public partial class Form1 : Form
{
public delegate void FooHandler(int myParam1, string myParam2);
public static FooHandler fooHandler;
public Form1()
{
InitializeComponent();
fooHandler = foo;
Form2 f = new Form2();
f.Show();
}
public void foo(int myParam1, string myParam2)
{
MessageBox.Show(string.Format("foo {0},{1}", myParam1, myParam2));
this.Text = "I was foo-ed";
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
if (Form1.fooHandler != null) Form1.fooHandler(2, "foo-you!");
}
}
|
|
|
|
|
thank you like this it would work.
my only question know is it also possible to change object property's on the other form in this same event handler
public void OpenNewMap(object sender, EventArgs e)
{
frmNewMap.ShowDialog();
if (frmNewMap.OkClicked)
{
tileset = frmNewMap.tileset;
texture = Texture2DFromFile(frmNewMap.TilesetTextureName);
tilesetBitmap = Bitmap.FromFile(frmNewMap.TilesetTextureName);
tileMap = new TileMap(frmNewMap.MapWidth, frmNewMap.MapHeight);
layerToolStripMenuItem.Enabled = true;
saveMapToolStripMenuItem.Enabled = true;
clbLayers.Items.Add(frmNewMap.TileLayerName, true);
clbLayers.SelectedIndex = 0;
clbLayers.SelectionMode = SelectionMode.One;
currentLayer = tileMap.layers[0];
FillPictureBox(0);
form2.nudCurrentTile.Value = 0;
form2.nudCurrentTile.Maximum = tileset.tiles.Count - 1;
this.Invalidate();
}
}
greetings twan
|
|
|
|
|
I need to export my Crystal Report 2008 rpt file into text format
Sanath
|
|
|
|
|
|
Hi Maciej Los,
Thank u so much.
|
|
|
|
|
You're very welcome
|
|
|
|
|
|
What kind of answer will you get when the question is "My Web browser is slow to watch a movie.., Please help me out".
To get answer, be specific with your question.
What kind of form exe it is?
What it does?
Why or how you say it is slow?
etc
|
|
|
|
|
hello sivaraman,
i made the windows forms application in c#. and crate the setup file and run the setup, then files related to application are goes down to c:\program files.... by default and create the desktop icon.
but when run the application it take more time to open forms.
but when setup run and change his destination other than C:\Program files to other drive it works fine.
then please help me about this problem.
thanks.
|
|
|
|
|
Make sure C:\Drive has More than 1 GB disc Space. Sometimes this will slow down the performance.
|
|
|
|
|
|
With the complete lack of information you've given so far, it's IMPOSSSIBLE to answer your question.
Without seeing your code and a description of how the app works and how it's designed, there's really nothing anyone can say that will be helpful.
|
|
|
|
|
We cannot create instance of an abstract class as abstract keyword is an indication to compiler not to consider the abstract class as a type.
If any it is just for initialization of properties/variables of abstract class then that can be achieved by private or protected constructor.
If you declare a public constructor in an abstract class then compiler will not give any errors.
|
|
|
|
|
First off, you can't use a private constructor in an abstract class, as you cannot create a derived class from it: the derived class cannot access the private constructor so you get a "is inaccessible due to its protection level" error from the compiler.
And that's kind of the clue as to why you can declare a public constructor: so that derived examples can be used in any assembly or class. Yes, you could use protected instead, and that would work - but it's not so obvious that it's allowed when you quickly read it!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Varun Thakur wrote: abstract keyword is an indication to compiler not to consider the abstract class as a type. Incorrect; an abstract class is also a type.
Varun Thakur wrote: If any it is just for initialization of properties/variables of abstract class then that can be achieved by private or protected constructor. Only members need be initialized, and one doesn't need a constructor for that either.
Varun Thakur wrote: If you declare a public constructor in an abstract class then compiler will not give any errors. Sound correct. Same does not apply to private methods btw.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have a form in which i an using tab control.
There are three tabs and in each tab there are textboxes.
What i want to achieve is that when i switch from tab 1 to tab 2. All the textboxes of tab 1 should be cleared.
Is it possible???
I am using Visual studio 2013, .NET 4.5, C#
|
|
|
|
|
Check the active index of tab on tab click and set the text box blank.
|
|
|
|
|
Thnx... I did consider your suggestion and used tab Deselecting event....
Thnx again...
|
|
|
|
|
Why the following code gives me this:
1000000000000000019884624838656
instead of
1000000000000000000000000000000
BigInteger result = new BigInteger(Math.Pow(1000, 10));
|
|
|
|
|
|
|
excuse me are you from iran
|
|
|
|