|
|
James Cheng Zhang wrote: add a control to the non client area of a form
What would be the point? I don't understand what you're trying to accomplish.
only two letters away from being an asset
|
|
|
|
|
The typical way to do this, is to remove the non client area, such as the title bar, and write your own replacement, adding your controls to it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I think i'll have to do that . Thanks
|
|
|
|
|
Hello everybody, I'm fairly new to the subject of c # ...
I think it is simple, I have two forms (Form1 and Form2) in Form1 is a RichTextBox, pressing a button on the Form1 open the form2, i add a button on form2 and when click they add string to richtextbox on form1. The question is do you all right it gives no error, but when I run the program does not add.
Form1---Click Button (in form1) | open form2 ------> Click Button(in form2) | Add string (Text) to richtextbox on form1.
I leave the code to see if any could pull a little help from and a thousand thanks!,
And I apologize for my bad English
Form1
namespace testrich
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
richTextBox1.AppendText("Original text");
}
public void button1_Click(object sender, EventArgs e)
{
Form Form2 = new Form2();
Form2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
this.Refresh();
}
}
}
Form 2
namespace testrich
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Form1 Form1 = new Form1();
Form1.richTextBox1.AppendText("-Attachment-");
}
}
}
|
|
|
|
|
Hi Lucas,
welcome to CodeProject.
seems to me you have more than one instance of Form1.
inside Form2.button1_Click, you create a new Form1, which is not the same
Form1 that caused Form2 to be created and shown; so changing the second Form1 will not
show any change on the first Form1, and since the second Form1 is not shown at all
(there is no Form1.Show) whatever you do to it will not show on the screen.
You need to pass the original Form1 (this) to Form2 when you create Form2, so it can
interact with its creator; or you could use delegates.
|
|
|
|
|
Hi Luc! Thank you very much for your answer so fast! , I see what the problem is, what happens now is that my knowledge in c # is not much, So I can not find how to make the call form 2 to Form 1 and not create another Form 1. I will read something about delegates :P , thank you very much again.
PD: Please if you know how to pass the original Form1 (this) when you create Form2 to Form2, tell! jejej =)
|
|
|
|
|
Seems you're in way over your depth here. Yes, delegates are the best way to get Form2 to talk to Form1. Plenty of info on the web. To pass the string from Form1, to Form2, just pass the text as a parameter, either on the constructor, or expose a property on Form2.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thank you very much Christian, I will try to seek and understand.
|
|
|
|
|
Hi again,
the easiest way (not the cleanest way) is like so:
1. add public Form1 Form1; as a member of class Form2; it will hold
the reference to an already existing Form1 object.
2. add Form2.Form1=this; just before you do Form2.Show();
that is where you provide the information about Form1 to Form2.
3. drop Form1 Form1=new Form1(); so the following line modifies the
existing Form1, not a new one.
Much cleaner and better would be to use a delegate; that way you do not have to
expose Form1 to Form2 (the former approach gives Form2 a chance to change much more
than you really need).
You should study delegates when you are a bit more familiar with C#.
I suggest you work your way through a C# book of your choice.
|
|
|
|
|
lucas moretti wrote: public void button1_Click(object sender, EventArgs e)
{
Form1 Form1 = new Form1();
Form1.richTextBox1.AppendText("-Attachment-");
}
Above code will create Form1 instance each time when you press button. This is the problem you are facing.
lucas moretti wrote: Form1.richTextBox1.AppendText("-Attachment-");
For the above code to work, you have to make richTextBox1 expose to outside of class which is not at all recommended.
To solve the problem, you can use either delegates or create a public method in the form1 and call it to update the richtextBox. Something like
public partial class Form2 : Form
{
public void UpdateTextBox(string text)
{
richTextBox1.AppendText(text);
}
public void button1_Click(object sender, EventArgs e)
{
Form Form2 = new Form2(this);
Form2.Show();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Form1 form1 = null;
public Form2(Form1 form1) : this()
{
this.form1 = form1;
}
public void button1_Click(object sender, EventArgs e)
{
form1.UpdateTextBox("-Attachment-");
}
} Same code can be written using delegates. You declare a delegate in Form2, and when showing the form2, form1 subcribe on this and will get notified when the text changes.
Hope this helps. Merry X'Mas.
|
|
|
|
|
Wiiiiiiiiii!
This works! Thank you very much! You're the best. Now that works fine, I will look at the issue of delegates =) . Merry X'Mas too xD
|
|
|
|
|
It works, but I'd tear strips off anyone who worked with me and did it. Make sure you study delegates in order to be able to move away from this sort of thing. You also need to understand how object oriented code works, and what the new operator does, because it's clear you don't from the code you wrote initially.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I dynamically created ten textboxes on a form(not by dragging controls from toolbox). How can i invoke the events of these controls such as keyPress event? Please help, Thanks.
|
|
|
|
|
Just call the method. i.e OnKeyPress(this, new KeyPressEventArgs(char to simulate));
only two letters away from being an asset
|
|
|
|
|
DEEPNORTH wrote: How can i invoke the events of these controls such as keyPress event?
Simply by registering an event handler:
private void TextBox_KeyPress(Object sender, KeyPressEventArgs e)
{
...
}
and this at creation of the textboxes:
TextBox t = new TextBox();
t.KeyDown += new KeyPressEventHandler(TextBox_KeyPress);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you all. You guys are great!
|
|
|
|
|
Hi,
the lines Greeeg has suggested are also the lines that Visual Designer would generate
when you would add TextBoxes at design time; you can always try a design change and
look at the code that gets added to the myClass.designer.cs file
|
|
|
|
|
hi,
use Grid view for search result in my web page.when i click on search button if there is result it gives properly according to my page.when there is no result it becomes small and on my page there is menu it looks big and search result is attached to it.It looks small.I tried to increase height of grid view but there is no effect.How should i solve this
Thanks
|
|
|
|
|
Try setting the gridview height explicitly
Regards,
Lev
|
|
|
|
|
Hi,
I fixed the height=500px but there is no changes.And it attached to menu it should looks very small.I need both height should be same
Thanks
|
|
|
|
|
when there is no result then in FireFox it won't display properly.But in IE it display correctly.So how should i do this
|
|
|
|
|
Hi,
I am writing a Windows Service in Windows Vista. I need to start a process. Can anybody please help me in writing C# code to get it done?
Thanks in advance
|
|
|
|
|
queries365 wrote: I need to start a process.
using System.Diagnostics NameSpace, then use Process Class
cheers,
Abhijit
|
|
|
|
|
Abhijit Jana wrote: queries365 wrote:
I need to start a process.
using System.Diagnostics NameSpace, then use Process Class
Hey Abhijit,
Thanks for replying
I have already tried this and it works fine in Windows XP. But in Windows Vista, the service starts and the process doesn't start.
Can you please give some Windows Vista specific help ?
Thanks and regards,
queries365
|
|
|
|