|
You need to pass an instance of the first form to your second form. For example:
public class Form1 : Form
{
internal Label label1;
private Button button1;
public Form1()
{
label = new Label();
button1 = new Button();
button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
using (Form2 form = new Form2(this))
form.ShowDialog(this);
}
}
public class Form2 : Form
{
private TextBox textBox1;
private Button button1;
private Form1 form;
public Form2(Form1 form)
{
this.form = form;
textBox1 = new TextBox();
button1 = new Button();
button1.Click += new EventHandler(button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
if (form != null) form.Label.Text = textBox1.Text;
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need to add bitmaps to some buttons, but they are tiny bit maps. Whats the best way to create these small buttons so the small bitmaps complete cover the button ?
|
|
|
|
|
Draw them yourself. Override OnPaint and use PaintEventArgs.Graphics to draw the Bitmap s using Graphics.DrawImage . Give it the bounding rectangle of the Button and the image will be stretched.
You could also try searching CodeProject. I know I've seen several articles covering this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First off thanks for the response. I have tried searching botht the artciles and messageboad but I cannot find anything on point.
I think I understand what you mean, but i'm not sure if that will give me what I want. I'd like to fit the button to the picture, not stretch the picture to the button. Is your solution still the same ?
I assume I will need to inherit the Button Class and create my own control in order to override the OnPaint() method ?
I've tried to create the buttons and fit to the picture using the code below, but for some reason the bottom of the picture is getting chopped off, or at least it appears to be.
Image ButtonPic = null;
Stream ImgStream=null;
int ImageHeight,ImageWidth,ButtonY,ButtonX=0;
ImgStream = this.GetType().Assembly.GetManifestResourceStream("MiniP3.PlayerPrevious.bmp");
ButtonPic = Image.FromStream(ImgStream);
btPrevious = new Button();
btPrevious.Image=ButtonPic;
btPrevious.Size = ButtonPic.Size;
btPrevious.ImageAlign=ContentAlignment.MiddleCenter;
ImageHeight = ButtonPic.Height;
ImageWidth = ButtonPic.Width;
ButtonY = (int)(pnButtons.Height-ImageHeight)/2;
btPrevious.Location = new Point(ButtonX,ButtonY);
this.btPrevious.Click += new System.EventHandler(this.PreviousClick);
pnButtons.Controls.Add(btPrevious);
|
|
|
|
|
Yes, the best way is to extend the Button class with your own. This makes it easy to add new image buttons as the derivative class encapsulates the code necessary to display an image.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I just found Marc Clifton's Article.
|
|
|
|
|
Hello All, I have an ASP.net application that is currently using the push method and displaying reports off of ADO.net datasets. I am struggling with a design method for the following questions:
1. .NET treats each crystal report you add to your project as a class and I am using a several reports and the ReportDocument class to set datasources for each one and so on. Depending on which report my users select in an aspx page i show them the report they want by creating an object of the type of report they selected. I am wondering if I can create say Object myobj = new Object() and depending on what report they select cast the general myobj object into the specific type of the report class the user selected instead of having to instantiate an instance of every type of report within my code?
Thanks for your help
Frank
|
|
|
|
|
Depending on how you display the list of reports, you can use Activator.CreateInstance to create an instance of the report. Cast that to the ReportDocument base class and call SetDataSource with your ADO.NET DataSet .
For instance, if you use a ListBox you could set the display name to whatever you want, but set the value for each item to the corresponding .rpt name. Since this gets compiled to a class with the same name using a namespace that is your project's root namespace (the project name by default) plus any folders it's in, you could do something like this:
string reportName = "MyWebApp.Reports." + listBox1.SelectedValue;
ReportDocument report = Activator.CreateInstance(reportName, "MyWebApp.dll");
report.SetDataSource(dataSet1); Of course, you should add error handling like try-catch blocks and conditionals (like checking for null values, etc., since throwing exceptions is expensive).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there any way to add a menu item to an existing drop down menu in Excel using the Visual Studio Tools for Microsoft Office 2003? I want to add a menu item to the drop down list you get when you right click on a cell on the worksheet. I also want to add an event handler for that new menu item.
Thanks for any help
Mike.
|
|
|
|
|
Hi,
I am getting an "its inaccessabile due to its protection level" error
here's my code:
<br />
public DataSet dsDiff; <- defined globally <br />
<br />
dsDiff.WriteXml(spath + @"\MidnightData.xml", XmlWriteMode.DiffGram);<br />
<br />
<br />
Any Ideas ?
Thanks,
JJ
|
|
|
|
|
Yes, but the class that it's defined in is either sealed or private or internal or something else.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
"Global" variables don't exist in C# or the .NET CLI. You also might want to cut and paste the exact error message since the one you typed isn't spelled correctly.
There might be a accessor problem with the DataSet or there could be a security issue with the path that your writing data to. We'll need the exact Exception message to find out.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
It was because I was using the wrong method argument for the dataset. I had it using a string sFilename when in order to use the XmlMode.Diffgram I needed to supply a XmlWriter object instead. So as soon as I supplied it the proper method arguments all was well.
Weird error message though !
<br />
public void WriteXml(<br />
XmlWriter writer,<br />
XmlWriteMode mode<br />
);<br />
<br />
Thanks,
JJ
|
|
|
|
|
Globel variable doesn't exist in C#. that is true. But if you want to access a variable Globally. what you will do ?
i have clear idea that how i can use a variable globally in C#. app.config
" dear friend you forgot this ".
Sreejith S S Nair
|
|
|
|
|
Globel variable doesn't exist in C#. that is true. But if you want to access a variable Globally. what you will do ?
i have clear idea that how i can use a variable globally in C#. app.config
" dear friend you forgot this ".
Sreejith S S Nair
|
|
|
|
|
Does anybody know if a c# program can run in 64 bit mode on Windows XP 64bit edition or Windows server 2003 64bit. I have some customers that have AMD Athlon 64 and asking me!
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
Dimitris Iliopoulos wrote:
Does anybody know if a c# program can run in 64 bit mode on Windows XP 64bit edition or Windows server 2003 64bit. I have some customers that have AMD Athlon 64 and asking me!
I'll take a stab at this--no, I don't think it will run in 64 bit mode. The JIT compiler doesn't know about 64 bit mode yet, and I don't think the .NET dll's are 64 bit capable either.
Of course, it'll still run fine, but in 32 bit mode.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
|
|
|
|
|
64 bit support won't show up until VS.NET 2005 and the .NET Framework 2.0. Exactly how much support remains to be seen though because not every technology Microsoft has will be 64-bit ready at the time the .NET Framework 2.0 and compilers are released.
Your app will run just fine as it is now on a 64-bit system.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hi,
If I call a web service and I can't connect to it for whatever reason, what exception will it call? From my reading it sounds like a SoapException error but not sure. If so what reference do I need in order to catch this SoapException?
Thanks,
JJ
|
|
|
|
|
It doesn't have to be a SoapException. The call could also throw a SecurityException, a custom exception thrown by the Web Method, ArgumentOutOfRange, ... ASP.NET could throw an exception. A SoapException is just one class of exceptions that could be thrown.
Your call to the WebMethod should be wrapped in Try/Catch/Finally blocks:
Try
Dim result As Integer = remoteClass.WebMethodCall(parameters)
Catch soapFailure As SoapException
' Code to execute in response to a SoapException
Catch soapFailure As SoapHeaderException
' Code to execute in response to a SoapHeaderException
Catch argFailure As ArgumentOutOfRange
' Code to execute if the args are out of whack.
' Which they shouldn't be if your doing validation! ;)
Finally
' This code will execute no matter what happens in the Try and Catch blocks...
End Try
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
I can't seem to find the ArgumentOutOfRange exception in c#, any ideas where its referenced from?
Thanks for replying,
JJ
|
|
|
|
|
Sorry, it's ArgumentOutOfRangeException and it derives as follows:
System.Exception.SystemException.ArgumentException.ArgumentOutOfRangeException
or just:
System.ArgumentOutOfRangeException
for short.
BTW: That's not the only Argument exception that can be thrown and writing seperate exception handlers for each and every class is VERY inefficient. You might want to handle entire classes of exceptions such as SoapException covers all SOAP failures with the body of the SOAP message. SoapHeaderException covers all those in parsing the SOAP header. Like I said, there a BUNCH of exceptions that can be thrown and handling all of them is not necessarily a good idea. You might want to read this[^] article on MSDN for an idea of how to handle unexpected failures.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, though I've been a member of this site for some time now I've not posted in the forums very often. Well, finally I've got a question that I couldn't answer in any other way (Including reading several books and asking for the assistance of some of my teachers in the MCAD).
According to the OO Programming model, every class attribute has to be marked as private and be made accessible to other classes throgh a Property. Now, in my class designs, I work a lot with ArrayLists as member of classes, so (and here comes the question)...
How can I create a property for an ArrayList? Is it done trough Indexers? (The same could be asked about arrays and any collection that belongs to a class, like Stacks, Qeues, Hash Tables, etc.).
Thanks for reading so far, I'd like to hear what you think about it.
morph3us
~~~~~~~~
only the phoenix arises
and does not descend
and everything changes
and nothing is truly lost
|
|
|
|
|
If you would like to provide a property for a ArrayList , just make the property return a ArrayList .
Simple.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|