|
I have this Windows app.
When the user clicks on a button (any button), after the event handler is done, the form is supposed to have focus returned (like if there's a MessageBox involved).
However, I've noticed that the user is forced to click once on the form to regain focus.
To illustrate (and this sounds weirder)...
The user hits a button, a MessageBox appears saying "are you sure?", and the user hits "no".
The messagebox disappears. But the button still has focus (understandable). If the user clicks on a different button, that same button still has focus and Windows thinks the user just clicked it instead of the other button that they clicked. The user has to click once on the form (even though the form visually seems to have focus, with the title bar dark blue and everything) before clicking on any other button.
Any ideas? This one really has me stumped.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Wouldn't you know it, almost right after I post this, I found it. I had the button's Validated event also pointing to the Click event handler. Now it works fine. Thanks anyway!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
I have a method which is run as a thread and at the end of it I have:
XtraForm2 form2 = new XtraForm2();
form2.Show();
and the thing is that the windows just flashes - opens and imidiately closes
how can I solve it??
|
|
|
|
|
Keep the thread alive while the form is shown. Easiest way to do this is probably use form.ShowDialog() rather than form.Show().
p.s. make sure this background thread is STA, or you will run into all kinds of odd problems.
|
|
|
|
|
hmm... I've tried ShowDialog() but the result is the same
I can't really get the idea of STA
I have a method
public void GetData(Object o)
{
...
}
which I'm starting from a button as a thread:
Thread wat = new Thread(new ParameterizedThreadStart(GetData));
wat.Start();
where the STA should be put?
|
|
|
|
|
STA indicates that the COM threading model for an application is single-threaded apartment.
Apply this attribute to the entry point method (i.e. the Main() method). It has no effect on other methods!
SkyWalker
|
|
|
|
|
a did somethling like this in my XtraForm1.cs
[STAThread]
public void GetData(Object o)
{
...
...
form2.ShowDialog();
}
but again it closes itself :/
I also have in the Program.cs file:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new XtraForm1());
}
|
|
|
|
|
Try this:
Thread wat = new Thread(GetData);
wat.SetApartmentState(System.Threading.ApartmentState.STA);
wat.IsBackground = false;
wat.Start();
...
void GetData()
{
form.ShowDialog();
}
Let me ask you a question, though: why are you creating a new thread to create the form? You're creating lots of extra work for yourself by creating a new thread to launch the form. If you keep all the UI controls created on the same thread, things will be much easier for you.
Thus, I recommend you create all your UI controls on the same thread.
|
|
|
|
|
you solution works just perfect thanks
the application looks like this:
I start it, and there is a button which is pressed and then the method GetData is started as a thread and after it processes all the data a second window pops up with a report, so I don't make a new thread for the second window
|
|
|
|
|
greetings for all, I am very instered in learn how work with sound in c#...
for instance load a music file, see the frequency of that, if any one have any idea or better have a project as example, please tell my,
regards
my;)
|
|
|
|
|
I believe in .NET 2.0 their is a System.Media namespace that has classes to handle wav sound files. If you are using .NET 1.1 or before (or if the classes in the System.Media namespace can't help you with your specific file format) then you might try using activeX controls. I know Windows Media Player has a control for video, but I am not sure whether they have a control for audio.
Now that I think of it, I remember somewhere on this site their is an article on audio output using Windows Media Player. Try searching.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
To just play a file, using Windows Media Player as a control works best. To work with sound directly, you need DirectSound, part of the DirectX libraries.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
sno-1 wrote: see the frequency of that
What does that mean
led mike
|
|
|
|
|
yes as you know, all word that we say, more or less, have a average in a frequency scale, but not wory, indeed I star now a project for do many things using this topic "sound", when I finish this a post that...
regards for all
|
|
|
|
|
If you just want to play WAV sound files, you can use System.Media.SoundPlayer . If you want to do advanced things like changing the frequency of sound files, you'll need to go outside the .NET framework for that. You can use DirectSound, part of DirectX. You could probably also use DirectShow, which is part of the PlatformSDK. There are DirectShow wrappers for .NET on this site if you care to search the articles.
|
|
|
|
|
You can also "execute" a sound file (as if double clicked in Explorer), using the
Process class;
please see the many messages that have popped up about this on these message boards...
Luc Pattyn
|
|
|
|
|
Hello,
I have several MDI child windows for my application. These show up in the Windows list dropdown menu when I open them. When the user clicks on the X to "close" the child window, I just want to hide it so I capture this in my FormClosing event handler for each of them doing this:
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
}
Which hides the child window just fine, however, when I want to redisplay it, clicking on the appropriate control to call Show() for that window, it displays just fine but I don't get an entry in my Windows list dropdown menu for that item.
Any thoughts?
Thanks,
Matt
|
|
|
|
|
How do they get into your drop down list to start with ? That's obviously where the problem is.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: How do they get into your drop down list to start with ? That's obviously where the problem is.
Well, I believe I just followed the steps outlined in the MS documentation to do this. I set my main form's IsMdiContainer property to true. I added a menustrip via the designer. The entries are added by setting the MdiWindowListItem property of the menuStrip to the desired menu item (In my test case, "windowToolStripMenuItem") from within the designer and then I call the following when I want form2 to show:
form2.MdiParent = this;
form2.Show();
The problem seems to me to be when I handle the FormClosing and set e.Cancel = true. I don't know what is going on behind the scenes to manage the list of windows that show up in the menu. I can call Hide() on form2 from its parent window, form1,and when I use the control to show form2 again it shows up in the window list as I would expect.
Anyway, thanks for the quick response.
Matt
|
|
|
|
|
Hey guys, I'm having a hell of a time trying to figure out how to save the current web page as an MHT from within my current asp application.
Basically, I want to do THIS (see link), but have it work under C# (not C++).
http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4397/
It doesn't like ANY of the commands, it says the directives are all wrong.
For what it's worth, I have MSADO15.DLL added as a reference.
Thanks,
Todd
Todd,
Fort Lauderdale
|
|
|
|
|
ASP is different to ASP.NET
Wow - that's a weird thing for ADO to offer. What does yuor code look like ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello folks.
I am writing an application which has two text boxes (call them A and B). B is a hexdump representation of the text in A. So far, so good. What I want that when text is selected in A the corresponding hex characters are highlighted in B, and vise versa.
I started with TextBoxes, but I needed to know when the selection in one box changed and TextBox doesn't tell you this. RichTextBox has the SelectionChanged event - perfect - so I switched to RichTextBoxes.
But now, whenever my selection extends beyond a space, RichTextBox starts selecting the entire word(s). I can't get it just select what I drag the cursor over. I have checked the AutoWordSelection property and it is set to false - I even checked it at runtime to see if had changed, but it is false at the moment my selection is being changed.
Does anyone have any ideas? Can this #!&^ "feature" be turned off in RichTextBoxes? Or can I go back to TextBoxes and get notification of a change to the selection?
Clive Pottinger,
Hamilton ON
|
|
|
|
|
Hi Clive,
I dont think you can change the selection mode the way you want it.
Even Wordpad does it like that: as soon as a selection crosses a word boundary, it extends to contain complete words only (so not only with spaces, try e.g. a period).
And yes I too dislike that.
Luc Pattyn
|
|
|
|
|
In my C# Winforms 2.0 application I have
Main form MenuStrip:
AllowMerge: True
Main form Menustrip File menu:
MergeAction: MatchOnly
MergeIndex: -1
MDI Child form base class MenuStrip: AllowMerge: true
MDI Child form base class MenuStrip File Menu:
MergeAction: MatchOnly
MergeIndex: -1
MDI Child form base class MenuStrip File Menu New item:
MergeAction: Insert
MergeIndex: 1
When I open child window, child menustrip menu item is not merged Main form.
Any idea what causes this ?
Andrus
|
|
|
|
|
Hello. Right now I admit defeat and don't know how to do this. I have a configuration file that I have to load at runtime and interpret. This works fine for all the settings in the appSettings sections but I don't know how to get the value from the system.diagnostics section.
This is an example of an config file (in "real" a lot bigger;))
<configuration>
<appSettings>
<add key="Hello" value="World" />
</appSettings>
<system.diagnostics>
<switches>
<add name="Trace" value="4" />
</switches>
</system.diagnostics>
</configuration>
To load the file I use the OpenExeConfiguration method and most of the data I can get to, but not the "Trace" value from the system.diagnostics.
<code>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration("c:\\projext1.exe");
MessageBox.Show(config.AppSettings.Settings["Hello"].Value);
ConfigurationSection sel = config.Sections["system.diagnostics"];
</code>
Does anybody have any idea on how to get the value? A possible solution might be to load the file into XML, but I'm still hoping on using the Configuration object. Hope you can stand my bad english and thanks to enybody that have a suggestion.
Edit: formatting... 
|
|
|
|