|
Sorry about that. I must not have seen the reference in your original post. You mention that you are placing controls in the group box in a "grid", what are you using to do this?
It sounds like you're doing this in order to prevent the control from flashing as you add new rows. Without handling the paint method yourself, I don't think there will be a way to do this.
You can do this pretty easily by creating your own GroupBox control. It should look something like this:
public class DelayPaintGroupBox : GroupBox
{
private bool paintAllowed;
public DelayPaintGroupBox()
: base()
{
}
protected override void OnPaint(PaintEventArgs e)
{
if (paintAllowed)
{
base.OnPaint(e);
}
}
public bool PaintAllowed
{
get
{
return this.paintAllowed;
}
set
{
if (this.paintAllowed != value)
{
this.paintAllowed = value;
}
}
}
}
|
|
|
|
|
Can anyone explain to me a simple way to write to controls from a thread that didn't create them. I've viewed the MSDN article and I just can't get it to work.
|
|
|
|
|
Here is an example using anonymous delegate:
public Boolean SafeEnabled {
get {
if (true == this.InvokeRequired) {
Boolean enabled = false;
MethodInvoker method = new MethodInvoker(
delegate {
enabled = this.Enabled;
});
Invoke(method);
return enabled;
}
else {
return this.Enabled;
}
}
set {
if (true == this.InvokeRequired) {
MethodInvoker method = new MethodInvoker(
delegate {
this.Enabled = value;
});
Invoke(method);
}
else {
this.Enabled = value;
}
}
}
Basically, you need to "Invoke" the method on the thread that created the control. You can use the Invoke method or the BeginInvoke/EndInvoke pair. The latter works like PostMessage in C++, the former works like SendMessage (if you are familiar with those).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Use delegates to change control text.
public delegate void ChangeControlTextDelegate(string _NewText, Control _Control);<br />
<br />
private void ChangeControlText(string _Newtext, Control _Control)<br />
<br />
<br />
if (control.InvokeRequired)<br />
{<br />
ChangeControlTextDelegatedCallback dCallback = <br />
new ChangeControlTextDelegate(ChangeControlText);<br />
<br />
this.Invoke(dCallback, new object[] { "newtext", control});<br />
}<br />
else<br />
{<br />
control.Text = "newText";<br />
}
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
I do what the other two have said. I used delegates, and I use BeginInvoke().
The reason I use BeginInvoke is - if your method which contains Invoke gets called again before the first Invoke has returned, your application can hang.
BeginInvoke() is asynchronous. So if you aren't super worried about performance, or don't need complete synchronicity, I recommend this approach.
|
|
|
|
|
Thanks everyone, this seems clearer. For some reason microsoft's examples just confuse me. This is probably because I'm so inexperianced. Thanks again.
|
|
|
|
|
|
// How do I make the current directory the
//same as where the program resides.
static void Main(string[] args)
{
int mode=0;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length == 0)
{
MessageBox.Show(Environment.CurrentDirectory);
// Current directory is where the program resides
// which is what I want
Application.Run(new Form1(mode));
return;
}
if (args.Length == 1)
{
MessageBox.Show(Environment.CurrentDirectory);
// Current Directory becomes \Documents and Settings....
// or \Program Files\Common Files\System\Mapi\NT and I want
// the CurrentDirectory to be the location of the program
mode = 1;
Application.Run(new Form1(mode));
return;
}
}
|
|
|
|
|
I think what you are looking for is:
Application.ExecutablePath
|
|
|
|
|
TNX
I was able to solve my problem although I still don't understand why the directory changes when there is a command line arg[0].
|
|
|
|
|
The current directory isn't set based on the location of the EXE. For command-prompts, it's based on the current directory. So if you have a command-prompt open to say "C:\Temp", then run your application like "C:\Blah\myApp.exe", then the current directory is "C:\Temp". For Windows short-cuts, you can specify the "Start in" directory, which is the same thing.
You can get the path to the entry assembly (the EXE in the general case) like so:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(assembly.Location);
Or check out the other response, which talks about Application.ExecutablePath
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
TNX Tom
Application.Executable Path solved my problem is there any disadvantage to doing things this way?
|
|
|
|
|
Not at all. If you use Reflector[^] you can view the code for this property. Internally, it uses GetEntryAssembly(), but also handles other cases. So Application.ExecutablePath would probably be the best way to go.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
This is why you never write code that uses the "current" directory. You ALWAYS write your code to generate fully qualified path names when working with files.
|
|
|
|
|
Hy
Can anybody tell me what is the difference between KeyPress event and OnKeyPress override? Why we need both? Why don't work in the same time, only one run?
thx
|
|
|
|
|
The KeyPress event can be used by the associated class or other classes. For example, a Form can listen for key pressed on a TextBox that it contains. The OnKeyPress method is used to fire the KeyPress event. This can only be used by dervied types. So if you create a custom TextBox (say MyTextBox), then you can override the OnKeyPress to catch key presses, alter when the KeyPress event is fired, fire another event, etc.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hello,
Way 1)
OnKeyPress ist the virtual method of a class, which can be overriden from an inherited class.
Way 2)
For handling the KeyPress event, you do not have to inherit a class.
You instanciate a class and handle the delegate.
All the best,
Martin
|
|
|
|
|
Hi,
I am currently writing an application that will dynamically load different applications and contain them in its own form (its an MdiManager Form). A big issue that I am running into is as follows:
When my main application loads and constructs another program, the child program is blowing up because the ConfigurationManager is using the main containing application's app.config. What I can't find....How in a dynamic environment do I get the current application's resulting exe name.
All of these classes are returning the name of the containing application:
Application.ProductName
Assembly.GetEntryAssembly().GetName().ToString()
I am trying to avoid hard coding "MyClass.exe.config" into each child application. I would much rather find a new method that I could use from now on instead of relying just on the ConfigurationManager. Thanks
|
|
|
|
|
You could get the path to the child application like so (assuming that the Program class below is in your child application):
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static String GetPath() {
Assembly assembly = Assembly.GetExecutingAssembly();
return System.IO.Path.GetDirectoryName(assembly.Location);
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, you can get the EXE name like so:
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static String GetExeName() {
Assembly assembly = Assembly.GetExecutingAssembly();
return System.IO.Path.GetFileName(assembly.Location);
}
}
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi friends,
My Requriment is When The Keyboard Left Key Is pressed it Works Like A BackSpace Key.
how to write a code in c#.
plz help me.asap.
regards
venkat.
venkat
venkat
|
|
|
|
|
Quick and dirty:
Setup a form with a text box
Add an event to that TextBox for the KeyDown event
Check if the key presses is Keys.Left
If so:
textBox1.text = textBox1.Text.Remove(textBox1.Text.Length - 1)
|
|
|
|
|
Quick and dirty:
Setup a form with a text box
Add an event to that TextBox for the KeyDown event
Check if the key presses is Keys.Left
If so:
textBox1.text = textBox1.Text.Remove(textBox1.Text.Length - 1)
|
|
|
|
|
Hello Friends,
Sealed cannot be inherited but it enables the run-time optimizations
Can anybody specify or explain this point
Thnx
.............
|
|
|
|
|
If you have a class that you don't want somebody to be able to inherit from, mark it as sealed. As the class is marked as sealed, the optimizer can perform certain optimizations such as transform virtual function member invocations into non-virtual invocations.
Deja View - the feeling that you've seen this post before.
|
|
|
|