This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I remove the selection border on a ListViewItem
I'm using the following code to make a Listview to use windows 7 native look and to prevent flickering.
Windows 7 Native Look for .NET ListView
http://geekswithblogs.net/CPound/archive/2006/02/27/70834.aspx
But I'm still getting a black dotted selection rectangle.
The question will be... How can I achieve the explorer selection rectangle?
Thank you so much for your help.
Based on the comment in the link provided by AVIDeveloper.
While the ShowFocusCues itself didn't work, the WM_CHANGEUISTATE
listed on that MSDN page led me to the right answer. By sending a
WM_CHANGEUISTATE message with UISF_HIDEFOCUS I was able to get rid of
the focus rectangle. – Telanor Apr 22 '10 at 17:11
I tried to find some information about this messages and eventualy saw this post: http://cboard.cprogramming.com/csharp-programming/128345-listview-remove-focuscues.html#post958690
So, we need to send the WM_CHANGEUISTATE message to the ListView in the constructor
SendMessage(Handle, 0x127, 0x10001, 0);
And we are only going to override the OnSelectedIndexChanged and OnEnter events.
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
SendMessage(Handle, 0x127, 0x10001, 0);
}
Without overriding the OnEnter event, the same black dotted selection rectangle will appear when the ListView gets the focus.
I tried to explain the best I could since I'm not a fluent English speaker and I'm going to wait if someone has a better answer before accepting mine.
Related
This question already has answers here:
Xamarin forms navigation back button
(3 answers)
Closed 3 years ago.
How can I intercept the back button events in xamarin forms for Android and IOS and be able to show the user an alert to confirm the exit?
The objective is to intercept the 2 buttons, the navigation menu (yellow) and the device (orange)
I have seen some examples, but they are several years old.
I am using VS 2019 and the latest version of xamarin forms.
Thank you in advance for your help.
You can Use Title View instead of default navigation bar and handle the back button event. Please refer: https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/TitleView
also you can handle device back button event by override it like this:
protected override bool OnBackButtonPressed()
{
//return true to prevent back, return false to just do something before going back.
return true;
}
Hope this may resolve your issue.
This question already has answers here:
C# RichTextBox selection problem
(2 answers)
Closed 7 years ago.
I only have form1 with RichTextBox (windows form) and I have no code.
Lets say we write "123456789" in RichTextBox via the keyboard.
The problem is: when I try to select number 9 from right to left by using the mouse then the whole text get selected automatically before even I select the rest of the text.
But I CAN select 9 from left to right without the rest of text gets selected. And also I CAN select number 1 from right to left and without the rest of text gets selected. The problem happens only when you select the last number from right to left.
you can select any number from right to left and the rest of the text does not get selected but if you select the last number from right to left then the whole text gets selected.
I checked the RichTextBox properties but nothing interesting there. TexBox does not behave like this but I do not want to use textbox.
My question is: How can I select number 9 from right to left in RichTextBox using mouse and avoid the whole text from being selected automatically. Thank you
See the answer given by Hans Passant, all credit goes to him.
(At this point I feel that giving him more rep is like taking a p*ss into Niagra Falls)
C# RichTextBox selection problem
In Hans' words:
There's a silly bug in the AutoWordSelection property implementation. The workaround is equally silly. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the existing RTB.
using System;
using System.Windows.Forms;
public class FixedRichTextBox : RichTextBox {
protected override void OnHandleCreated(EventArgs e) {
base.OnHandleCreated(e);
if (!base.AutoWordSelection) {
base.AutoWordSelection = true;
base.AutoWordSelection = false;
}
}
}
I could definitely replicate this behaviour before, and the custom RichTextBox fixed it for me.
I have a WPF .NET 4.6 application running on a Windows 8.1 tablet and for the last few days I've been struggling to make my app touch friendly to make it work as expected. My main problems are focus related, these affect several controls in my app. for example:
Textboxes: sometimes requires a double or triple touch in order to get input focus, they do enter a mouse over state but the caret isn't there;
ComboBoxes: takes a couple of touches in order to open it, and once touching an item in order to select it the combo stays open with the newly selected item highlighted;
Buttons: takes a couple of clicks to run the connected command and stay in mouse over state;
Keyboard support
There are a couple of approaches I tried while searching for a solution that each has it's own downsides:
Removing the tablet support for the entire application (taken from here). this one solves most of the focus problems mentioned above but makes scrolling (and I guess some other Tablet related functionality that I haven't found yet) unusable.
Explicitly activating the keyboard when required (Example here). Focus problem remains, scrolling works as expected
I also tried to remove all styles and tested everything on 2 different tablets from different manufacturers but without success
Recently Microsoft announced that "Touch is better" But I couldn't find any official documentation about the best way to approach this subject.
Any suggestion on how to make my application work better with touch would be a big help.
I was able to remove mouse over state by using following behavior:
public class TouchDeviceMouseOverUIElementFixBehavior : Behavior<UIElement>
{
protected override void OnAttached()
{
AssociatedObject.StylusUp += AssociatedObject_StylusUp;
}
protected override void OnDetaching()
{
AssociatedObject.StylusUp -= AssociatedObject_StylusUp;
}
private void AssociatedObject_StylusUp(object sender, StylusEventArgs e)
{
var control = sender as FrameworkElement;
if (control != null)
{
if (!VisualStateManager.GoToElementState(control, "Normal", true))
{
VisualStateManager.GoToState(control, "Normal", true);
}
}
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'll try to be as specific as possible. I'm using visual basic 2010 c# express edition. I'm trying to create a textbox that is filled with information from the program. Suppose I put the text "Hello" in the textbox, when I run it, the form has a textbox saying Hello.
Here, the user can select the text and copy it. Basically, when the mouse goes over the textbox, it changes appearance and the textbox is interactive.
What I need to make is the textbox as not-interactive. In the textbox properties, there is an option called "Enabled". If I make it as False, all my requirements are satisfied. But the textbox is greyed out. Is there any way to get "Enabled" to false and still make the textbox look not greyed out. My query is regarding aesthetics.
You can make the textbox readonly:
Creating a Read-Only Text Box (Windows Forms)
To make the background gray, you probably need to change the background color:
txtFoo.BackColor = ...;
And if you do no want to make the text selectable, set Enabled = false;
You can create your own control that will look exactly like a TextBox but will be static. It's very easy to achieve that. Right-click on your project name in Solution Explorer and choose: Add > New Item... > Custom Control. You can name it somehow, e.g. DisabledTextBox.
Here's the full code of the new control.
public partial class DisabledTextBox : Control
{
public DisabledTextBox()
{
InitializeComponent();
DoubleBuffered = true; // To avoid flickering
}
protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.Clear(SystemColors.Window); // White background
pe.Graphics.DrawRectangle(SystemPens.ActiveBorder, new Rectangle(0, 0, Width - 1, Height - 1)); // Gray border
pe.Graphics.DrawString(Text, Font, SystemBrushes.WindowText, 1, 3); // Our text
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
Invalidate(); // We want to repaint our control when text changes
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Height = Font.Height + 7; // This limit the height of our control so it will beahave like a normal TextBox
}
}
When you compile it, your new control will be available in Toolbox, so you can use like any other control. It will look exactly like TextBox.
textBox.BackColor = System.Drawing.SystemColors.Window;
Setting ReadOnly property to True should do the trick
I was looking for the easy solution to this question>
Here is what worked for me:
textBox Enabled property -- true
textBox ReadOnly property -- true
And below line of code to get rid of they greyed out area.
public Test_class()
{
InitializeComponent();
textBox.BackColor = System.Drawing.SystemColors.Window;
}
Yes, the user still can select the value in the text box but not entering a new value or edit old one.
Cheers!
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++).