Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am currently trying to develop a custom keyboard for WinCE application.Currently I have a form with a text box and a button. The issue is how can I maintain the focus on the keyboard when I click on the mouse to SendInput (to make sure that the textbox capture that input). One way is to set the "Focusable" property but I can't seem to set that on a Windows Form. I hope someone could help me on this. Thanks!
If you are not afraid of moving to the native side you may consider to implement a Software Input Panel (SIP). It will behave in the way you describe and can be used by any application running on the device.
This documentation is for Compact 2013, but it's also valid for previous releases (you can find release-specific versions on MSDN but they were pretty good in hiding them):
http://msdn.microsoft.com/en-us/library/ee500563.aspx
You should set the TextBox.Focus() on the button press event handler. I assume the button has a KeyPress or KeyDown function.
A more flexible alternative would be to store the last focused control.
private Control lastFocusedControl;
And when the text box is focused on it sets the value using the GotFocus event.
private void TextBox_GotFocus(object sender, EventArgs e)
{
lastFocusedControl = (Control)sender;
}
And then in the event handler you can simply do.
lastFocusedControl.Focus();
Although it is for VB.Net it has some good ideas: http://msdn.microsoft.com/en-us/magazine/hh708756.aspx
See WS_EX_NOACTIVATE and
If (m.Msg = WM_MOUSEACTIVATE) Then
m.Result = MA_NOACTIVATE
Else
MyBase.WndProc(m)
End If
Now the challenge is to adopt this to your idea (a separate process and form? or a panel with buttons?).
OTOS MS provides a custom keyboard SDK API set to write custom software keyboards for Windows Mobile (c/C++).
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
I'm making a "web browser" in C#, and I'm coming across problems. I don't think my button to go to the navigated URL is working, and I don't know how to test it. When you click the button, it runs mainBrowser.Navigate(urlTextBox.Text);, but that's not working for some reason. This is my code:
private System.Windows.Forms.GroupBox browserGroup; //container of sorts
private System.Windows.Forms.TextBox urlTextBox; //self-explanatory
private System.Windows.Forms.Button navigateToURL; //button to go
private System.Windows.Forms.WebBrowser mainBrowser; //browser
private void navigateToURL_Click(object sender, EventArgs e) //on the button's click
{
mainBrowser.Navigate(urlTextBox.Text);
}
What am I doing wrong?
PS: I literally just started c# today.
I suppose you are using Visual Studio IDE ...
So, here are some directions for you to start debugging and solve it yourself:
Place a breakpoint inside the 'navigateToURL_Click' event handler method. Run on debug mode, add a URL to the URL text box and check if you can catch the 'navigateToURL' button click there.
If that doesn't work, check the button 'Click' event in the button properties dialog. It should point to your 'navigateToURL_Click' method, as seen in this next image:
On the other end, if that breakpoint works, you can debug and watch the 'urlTextBox.Text' value to see if it is correct.
That's the idea of debugging (an inseparable part of any coding), from here you can think of more checks & test ideas like this ...
Good luck with C#... Have fun coding ...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Pretty much new to Windows Forms, I know the C# language, just not in the same context. I have searched around for a while and it seems to me that every solution is doing something similar to this:
Label1.Text = "I'm a label".
But I don't understand where Label1 is coming from.
All I have is a new Windows Form Application, which comes with one form preloaded and a Program class. So as this class came with some code, I thought this would be a logical way of accessing the label's properties:
static class Program
{
static void Main(String[] args)
{
FormUpdate frmUpdate = new FormUpdate();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(frmUpdate);
// Why isn't this a suitable way of getting the label?
frmUpdate.label1.Text = "I cause an error!";
}
}
But I don't understand where Label1 is coming from.
Someone used the Visual Studio Designer for Windows Forms and dragged and dropped a Label component onto their form. As Visual Studio has no way of naming them, but needs a name, it simply counts up. The first dropped label is called "Label1".
The access specifier for those controls added is private by default and I'd suggest to leave it that way. If you want to interact with your form, either do it from inside your form or write a public method that you call that will then set all the private properties like the text of a certain label.
Generally speaking, Application.Run(frmUpdate); is running the program, based on the starting form you gave. Anything after that will have little effect. So you ran your form and after you closed it, you set the label. That's not going to have any visible effect. You need to do that before you run the form or while you are running it.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have an issue that I can't seem to resolve via Google (likely because I'm not searching the right criteria). I have a Closing Event that checks if a button is enabled and pops a messagebox with a result (Yes/No). If the user says NO, I get the desired results in the app; however, the X in the top right corner stops working. How to I "reinstate" the close button ("X" in the top right hand corner) so it works again if pressed (and also evaluates the logic again).
I tried this: Stackoverflow Question
i don't think I want to play with Visibility of the window. The window doesnt go anywhere. They have dirty data and they need to fix it or have it auto saved.
What I have in the application is:
private void DXWindow_Closing(object sender, CancelEventArgs e)
{
if (BtnPatSave.IsEnabled == false) return;
if (MessageBox.Show(Properties.Resources.PatAcctMsgBox3, Properties.Resources.PatAcctMsgBox1,
MessageBoxButton.YesNo,
MessageBoxImage.Warning) == MessageBoxResult.No)
{
e.Cancel = true;
}
else
{
var patId = TbPatId.Text;
var usl = new UnSetLockValue();
usl.UnSetVal(patId);
Log.Info("Patient Account is now unlocked by user: " + Environment.UserName);
}
}
Thats because you are using the MessageBox class.
It disables the "X" button to allow the user only to provide the values you specify.
If you don't want this behaviour i think you have to create your own "MessageBox".
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've a c# project in which a form hides itself after some background task finishes, to be opened on command, but under certain conditions, the call to this.Show() or setting this.Visible to true doesn't make the form reappear! I even had the state of the form's Visible value output to be sure, and the form seems to think it's on screen, but it's nowhere to be seen.
The condition that seems to cause it to break is if I give another window control before the form hides itself. If I let it stay in front while it's working, hide itself, then tell it to come back it always does, even if I change focus after the fact, but I change focus away beforehand, it doesn't reappear, even though form.Show appears to be called.
Does anyone have any insight as to why this might be happening? It's such a weird case, especially since the state of form.Visible changes.
public partial class testForm : Form {
private void testForm_Sometrigger(object sender, EventArgs e) {
//some delay. In the actual program, this is thanks to a background worker working.
Thread.Sleep(5000);
//manually change focus to another process/window before this
this.Hide();
//I've been adding a wait here, since in practice the form won't be called again right away.
Thread.Sleep(3000);
//show form again.
this.Show();
// this will be true even if the form isn't actually visible
Console.WriteLine("is visible? "+this.Visible.ToString());
}
}
Code block added upon request. There isn't much to this bit, just showing and hiding and time passing, really.
Turns out the window not appearing probably has something to do with form inactivity and the UI thread not coming back to it, so adding a Form.Activate() after the show call fixed it.
Original question updated with solution.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Using combobox at C#, VS 2010, Forms.
After you drop a combobox, you scroll on list of choices with your mouse. Which event triggers this on MSDN Combobox Events
example: list of choices on combobox are apple, banana, chocolate, etc., you point at apple it calls the event, you point on banana it calls the same event, etc.
Also how do I get the values its pointing at?
If there is no event available, can I make one via program?
Been googling for a long time now can't seem to find what I need.
Which event triggers on this...
If you create a combo box and add items, you can set the SelectedIndexChanged event and set it to your own custom event handler, like this:
comboBox1.Items.Add("Apple");
comboBox1.Items.Add("Banana");
comboBox1.Items.Add("chocolate");
comboBox1.SelectedIndexChanged += ComboBox1OnSelectedIndexChanged;
The method receives a sender object that is of type combobox, the only tricky thing is that the signature sets it to an object. Casting it allows us to pull out the value.
private void ComboBox1OnSelectedIndexChanged(object sender, EventArgs eventArgs)
{
myvalue = ((ComboBox)sender).SelectedValue;
}
Seems like you could get what you want from this
Redrawing of owner-drawn winforms combobox items
specifically when
(state & DrawItemState.HotLight) > 0
Let me know if more explanation is in order.
EDIT --
What I mean is, by implementing ownerdraw, you are made aware of what item the mouse is over. When the mouse is over the item, then, per the linked article
((state & DrawItemState.Selected) > 0) || ((state & DrawItemState.HotLight) > 0)
is true.
So in that case you can fire an event as needed with the info the OP wants.