Remove the Close button in the program's title bar - c#

Goal:
Don't want the user to use the X mark (upper right of the program's screen) to exit the program.
Problem:
Don't know how to remove that icon that allows user to exit the program?

You can set the ControlBox property to false if you don't want this to display. This will also remove the minimize and maximize buttons, mind you.
I would also ask you to consider why you want to remove this button. Sometimes it makes more sense to override the OnFormClosing method and optionally set Cancel to true under certain conditions (e.g., e.CloseReason == CloseReason.UserClosing).

myForm.ControlBox = false;
Apparently I have to have at least 30 characters in my post, so I will say that I am assuming WinForms since you do not specify yourself. Also note that setting this property to false will remove the minimize and maximize buttons as well.

myform.ControlBox = false;
does it for me

This guy seems to have figured it out:
http://blogs.msdn.com/b/atosah/archive/2007/05/18/disable-close-x-button-in-winforms-using-c.aspx

I used this and its working for me
this.ControlBox = false;

Related

How can I close a NotifyIcon BallonToolTip from code?

We are using a NotifyIcon to alert the user when they receive a new message that needs their attention. In the event that someone else gets to the message first, the notify icon should get hidden again, however I am having a problem with figuring out how to close the balloon from code behind.
My code looks something like this:
myNotifyIcon.ShowBalloonTip(2000, title, message, icon);
I have tried the suggestions found here, but none are suitable.
Using myNotifyIcon.Visible = true does not hide it
Using myNotifyIcon.Visible = false; myNotifyIcon.Visible = true; will hide it, but it also hides the icon in the tray and when it is shown again, it shows up a a different location.
myNotifyIcon.Show(0) is not a valid method
myNotifyIcon.ShowBalloonTip(0) or myNotifyIcon.ShowBalloonTip(1) does not appear to work as the balloon just gets shown and doesn't appear to go away on its own at all.
I read this question about using the WinAPI to find the window and send it a WM_CLOSE message, but I'm not too sure how to do that reliably.
How can I close a NotifyIcon from the code behind?
I've never found a non-hacky way to do that. The documentation says:
Minimum and maximum timeout values are enforced by the operating
system and are typically 10 and 30 seconds, respectively, however this
can vary depending on the operating system. Timeout values that are
too large or too small are adjusted to the appropriate minimum or
maximum value.
Even though this does not specifically address the question of explicitly closing the balloon, it indicates to me that callers of the ShowBalloonTip() method simply do not have complete control over the balloon, once it's been shown.
The best option I've found is one you already mentioned:
myNotifyIcon.Visible = false;
myNotifyIcon.Visible = true;
Not ideal, but it works. Another idea would be to change the message displayed in the balloon to indicate that the previous message is obsolete:
myNotifyIcon.ShowBalloonTip(2000, "Title", "Never mind!", ToolTipIcon.Info);
There is a simple way to do that.
myNotifyIcon.ShowBalloonTip(2000);
myNotifyIcon.visible = true;
this.Hide();
Try this, it'll definitely work 100%.

How to disable PageUp/PageDown in ListView?

instead of jumping to the beginnng/end of the ListView, I would like to perform some other operation. So I would like to disable jumping through the ListView with PageUp/PageDown and perform some other operation.
I thought I could do sth. like
ListView.PreviewKeyDown
and do a
e.Handled = true,
but it is only possible to set
e.Handled = true
in
ListView.KeyUp.
But when trying to catch PageUp/PageDown in
ListView.Keyup,
the selection has already jumped to the beginning or end.
So how can I disable jumping to the beginning/end and perform instead an other operation?
Use OnKeyDown instead.
However, I have to advice against changing something basic like this. Users expect a certain thing when pressing page up / down inside a list view. Overriding this behavior makes it harder for your users to use your application.

Custom dialog box in wpf issue

I'm calling my custom dialog window with this code:
GUI.SLDialog sd = new GUI.SLDialog();
if (sd.ShowDialog() == false)
{
return;
}
But sd.ShowDialog() always returns nothing (i think), because the function breaks, but the waypoint at return; isn't reached.
Dialog is automaticly closing when I add to button:
this.DialogResult = false;//or true
Anybody know what am I doing wrong?
Thanks in advance for your help.C.H.
#edit
This is my SLDialog:
xaml: http://wklej.org/hash/9fb67fb0c7c/
cs: http://wklej.org/hash/16e3ccc6c0d/
I don't think I can tell you much here unless you post the code for the dialog but I do have a suggestion in the mean time.
Since you're already unhappy with the standard dialog boxes and customization is clearly an option why not move towards what people are coming to expect? Instead of your standard dialog why not just create a user control that lays over the rest of your UI and blurs everything out from the background? Much like a jquery dialog box you might see on a web page.
Modality is easier to control since it's just a matter of covering your entire app window with a translucent rectangle and then make the dialog window appear however you want.
Just a suggestion.

Followup: Bring a window to the front in WPF

I'm trying to add a button to my current project that when pressed will send the window to the back for x-seconds, allow the user to work in other windows, and then automatically come to the front again. By combining How to send a WPF window to the back? and Bring a window to the front in WPF, along with a BackgroundWorker, I was able to get this 99% done. When the button is pressed, the window goes to the back, and returns the specified number of seconds later. The problem is that if I go into another window (Opera, Word, etc), it never return from the back. I tried playing with the flags, but can't seem to get it to work. Is this possible to do? And if so, how?
Thanks!
With a hack it's possible. Just do that:
Topmost = true;
Topmost = false;
and the window should be in front.

Set a disabled TextBox's ForeColor to be the same as its BackColor in C#

How do I set a disabled TextBox's current text color to be the same as its current background color in C#?
Simply doing txtLala.ForeColor = txtLala.BackColor does not seems to work.
This works:
txtLala.Text = "Red";
txtLala.BackColor = System.Drawing.Color.Red;
txtLala.ForeColor = txtLala.BackColor;
txtLala.ReadOnly = true;
Try setting the color, before the readonly. And also check how you are setting the color!
EDIT
Try this
txtLala.Attributes.Add("style","background-color:Red;color:Red");
If you are trying to make it invisible, you know you can set it as
txtLala.Visible = False;
EDIT II
I finally tried
txtLala.Enabled = false;
... you see that grey shadow color! I don't think you can mess with that, it looks to be a browser property setting.
Why not set as ReadOnly or Visible = False?
Maybe you have a good reason for Enabled = false
But you should note:
Use the Enabled property to specify or determine whether a control is functional. When set to false, the control appears dimmed, preventing any input from being entered in the control.
Note The ability to enable or disable functionality is always available. However, dimming and locking the control only works in Microsoft Internet Explorer version 4 and later.
This property propagates down the control hierarchy. Therefore, disabling a container control will disable all child controls within that container.
Note Not all controls support this property. See the indivual controls for details.
It seems to only work for TextBox that is read only. If it is disabled (.Enabled = false). It does not seems to work.
If this is a readonly textbox, you need to explicitly set your BackColor first, then your statement will work.
txtLala.BackColor = System.Drawing.SystemColors.Info;
txtLala.ForeColor = txtLala.BackColor;
Ref: http://bytes.com/groups/net-c/233961-read-only-textbox
Then again, if it's readonly, a label might be better. If you're trying to hide it, perhaps setting .Visible = false would be better still.
Edit: This seems to be a common question on the web. With respect to winforms: This site suggests dropping the box into a frame and setting Enabled = false on the frame, not the textbox. Once you do that, you may be able to maintain control of the forecolor.

Categories