How can I make a .NET MAUI app to always be on top, top must, always visible?
I'm looking for an equivalent of Topmost="True" that we have in WPF.
I tried managing the UnFocused event and calling Focus(), but I had no luck:
private void Shell_Unfocused(object sender, FocusEventArgs e)
{
(sender as AppShell).Focus();
}
private void Shell_Disappearing(object sender, EventArgs e)
{
(sender as AppShell).Focus();
}
As suggested by Ralf, TopMost is a Windows Feature and that's a feature request can be tracked here:https://github.com/dotnet/maui/issues/8198.
If you want the feature works in Mac, you can follow up with Add "Topmost" shell/app feature
.
Related
I just started working on C# with Visual Studio & Windows Forms Applications. I was trying to create a Calculator and I was wondering if I could change the cursor type on a button which is disabled, I can't figure out how to do it, please help me thank you!
Edit: here's the code I tried to do, it only works if the button's enabled...
private void txt_current_operation_MouseHover(object sender,EventArgs e) {
txt_current_operation.Cursor=Cursors.Hand;
}
Hack Answer
Assuming the Button is contained by the Form, you can handle the MouseMove event of the Form and change the cursor from there:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rc = txt_current_operation.RectangleToScreen(txt_current_operation.ClientRectangle);
this.Cursor = rc.Contains(Cursor.Position) ? Cursors.Hand : Cursors.Default;
}
If the Button was contained by a Panel, or some other container besides the Form, then you'd change to the MouseMove event of that container instead.
Demonstration:
I have done a bit of research but cannot seem to find what I am looking for.
What I want to do is make a "custom" button in a windows form. This would basically just be a matter of changing the default "grey" background to a custom image. A custom image would also be used for when hovering over and clicking the button.
This is not just a matter of changing the background image as the image I want to use has rounded edges with a transparent background and I want custom image for hovering / clicked. I want everything else about the button to behave in the same manner as a normal button.
Is this possible?
It is called owner-drawn button
refer to:
Mick Dohertys' .net Tips and Tricks - Tips / Button
GlowButton - A Glowing Button Control
A shiny orb button in GDI+
The solution I found was to set the FlatStyle of the button to Flat and set all the borders to 0. I then had a problem with the focus of the button (it displayed a little border). To solve this I followed this tutorial:
http://dotnetstep.blogspot.com/2009/06/remove-focus-rectangle-from-button.html
With this in place all I had to do was add events to the button so that the image was changed when a certain action was carried out on it:
private void button1_MouseLeave(object sender, EventArgs e)
{
this.button1.Image = Properties.Resources._default;
}
private void button1_MouseEnter(object sender, EventArgs e)
{
this.button1.Image = Properties.Resources._hover;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
this.button1.Image = Properties.Resources._clicked;
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
this.button1.Image = Properties.Resources._default;
}
Hope this will help someone else!
In Visual C++ MFC there is an inbuilt mechanism for setting the menu item states. I am trying to do the same with C# and a WindowsForm object.
I found this which is not quite the same:
Grey out menustrip items when certain forms are open/active/focused
Here is my menu structure:
So, I decided to try this:
private void viewToolStripMenuView_Click(object sender, EventArgs e)
{
zoomExtentsToolStripMenuItem.Enabled = viewCtrl != null;
}
It kind of works. But I am a bit picky. I can see the menu displayed with the item enabled and then I see it change to disabled.
What is the right way to set the menu item states before the menu is displayed? I know this sounds like a simple issue but I can't find the equivalent methodology to ON_UPDATE_COMMAND_UI.
I was using the wrong event handler!
private void viewToolStripMenuView_DropDownOpening(object sender, EventArgs e)
{
zoomExtentsToolStripMenuItem.Enabled = viewCtrl != null;
}
I'm new to WPF and coming from a C++ background so maybe I'm worry about memory management too much here.
Anyways, I've got a UserControl (NewContact) that has a grid with 2 columns, upper column displays 3 radio buttons and depending on which is selected it loads the appropriate UserControl into the lower section of the grid.
private void newMilitaryContactRadioButton_Checked(object sender, RoutedEventArgs e)
{
UserControl NMC = new NewMilitaryContact();
NewContactWindowGridDisplay.Children.Insert(1, NMC);
}
private void newMilitaryContactRadioButton_Unchecked(object sender, RoutedEventArgs e)
{
NewContactWindowGridDisplay.Children.RemoveAt(1);
}
private void newLegalContactRadioButton_Checked(object sender, RoutedEventArgs e)
{
UserControl NLC = new NewLegalContact();
NewContactWindowGridDisplay.Children.Insert(1, NLC);
}
private void newLegalContactRadioButton_Unchecked(object sender, RoutedEventArgs e)
{
NewContactWindowGridDisplay.Children.RemoveAt(1);
}
private void newFirmContactRadioButton_Checked(object sender, RoutedEventArgs e)
{
UserControl NFC = new NewFirmContact();
NewContactWindowGridDisplay.Children.Insert(1, NFC);
}
private void newFirmContactRadioButton_Unchecked(object sender, RoutedEventArgs e)
{
NewContactWindowGridDisplay.Children.RemoveAt(1);
}
Now my question is whether I should be, and how to, unload the UserControls I create, when a radio button is unchecked. I did some searching around MSDN documentation and saw that the using the remove method from the parent object would unload the usercontrol. If that is the case is the code I'm using to in the various "unchecked" methods correct so as not to pile up a ton of NFC/NLC/NMC UserControl objects if someone were to click amongst the three radio buttons over and over and over again?
Much thanks to anyone to who can explain this to me :)
Actually you need to read more about .Net memory management and know how it works. In your case it depends on what your UserControls are doing? If they are using system resources it will good to dispose their references in UserControl unloaded events, otherwise GC will take care of them.
Read this article :
Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework
Also the way you are going is not so good, because soon you will find out you need to do more with your UserControl like setting its DataContext, Styles handling events and etc... and this will hard to do with code.
Is it possible force the build in keyboard to appear within a Windows CE 5.0 application?
I am designing a project in C# and would like the keyboard or a numerical keypad to pop-up when the user has to input to the application.
You should look at the InputPanel control. Just drop one onto your form from the toolbox. Then just show and hide it on the GotFocus and LostFocus events of the input controls:
private void textBox1_GotFocus(object sender, EventArgs e)
{
inputPanel1.Enabled = true;
}
private void textBox1_LostFocus(object sender, EventArgs e)
{
inputPanel1.Enabled = false;
}