This maybe a simple question...I want to disable Minimize/Maximize component from RichTextBox.
I tried to check the properties of RichTextBox, I couldn't succeed to disable these components.
I want to keep the x close component but I want to disable Minimize/Maximize component from RichTextBox.
private void button1_Click(object sender, EventArgs e)
{
ShowRichMessageBox(FileSelected, File.ReadAllText(FileSelected));
}
private void ShowRichMessageBox(string title, string message)
{
RichTextBox rtbMessage = new RichTextBox();
rtbMessage.Text = message;
Form RichMessageBox = new Form();
RichMessageBox.Text = title;
RichMessageBox.Controls.Add(rtbMessage);
RichMessageBox.ShowDialog();
}
The idea is to display a message in a RichTextBox of the read file.
Use the MinimizeBox and MaximizeBox properties of the Form.
Try this:
private void ShowRichMessageBox(string title, string message)
{
RichTextBox rtbMessage = new RichTextBox();
rtbMessage.Text = message;
Form RichMessageBox = new Form();
RichMessageBox.Text = title;
RichMessageBox.MaximizeBox = false;
RichMessageBox.MinimizeBox = false;
RichMessageBox.Controls.Add(rtbMessage);
RichMessageBox.ShowDialog();
}
RichTextBox control doesn't have Minimize button, only form has it. If you wont to remove form minimize and maximize button add this lines before showing a form :
RichMessageBox.MaximizeBox = false;
RichMessageBox.MinimizeBox = false;
Related
This is my code for a button in C# windows forms. I want the Tooltip to show whenever I hover, but it only works after I insert some text in the textbox
this is the code
private void passwordTextBox_TextChanged(object sender, EventArgs e)
{
ToolTip toolTip3 = new ToolTip();
toolTip3.AutoPopDelay = 5000;
toolTip3.InitialDelay = 1000;
toolTip3.ReshowDelay = 500;
toolTip3.ShowAlways = true;
toolTip3.SetToolTip(this.passwordTextBox, "Not more than 50 characters, no special charachters!");
}
you have set tooltip on wrong event. Best way is to set tooltip on Form Load Event.
private void Form1_Load(object sender, EventArgs e)
{
this.setToolTip();
}
private void setToolTip()
{
ToolTip toolTip3 = new ToolTip();
toolTip3.AutoPopDelay = 5000;
toolTip3.InitialDelay = 1000;
toolTip3.ReshowDelay = 500;
toolTip3.ShowAlways = true;
toolTip3.SetToolTip(this.passwordTextBox, "Not more than 50 characters, no special charachters!");
//Tooltip for other controls
}
Let me know if you still face any issue.
I have an application that goes to system tray when I minimize it. I created a notify icon to handle some secondary options for the app using right click from mouse using that notify icon.
But I would like the application not to disappear from task bar when I minimize it and mantain the notify icon on system tray.
Is there any way to acomplish thtat?
EDIT: When I minimize the application, I use the Hide() command to use the NotifyIcon. But I want it to remain on task bar.
See code here:
private void MainWindow_OnStateChanged(object sender, EventArgs e)
{
if (WindowState != WindowState.Minimized) return;
Hide();
ShowInTaskbar = true;
if (notifyIcon != null)
notifyIcon.ShowBalloonTip(2000);
}
Note: This NotifyIcon is embeded on a WPF container programatically like this:
DrawNotifyIcon();
private void DrawNotifyIcon()
{
try
{
string source = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MainWindow)).CodeBase);
string tmpSource = source + #"\Resources\mainico.ico";
tmpSource = tmpSource.Replace(#"file:\", "");
// notify Icon
notifyIcon = new NotifyIcon
{
BalloonTipTitle = Cultures.Resources.Title,
BalloonTipText = Cultures.Resources.NotifyIconExecuting,
BalloonTipIcon = ToolTipIcon.Info,
Icon = new System.Drawing.Icon(tmpSource)
};
notifyIcon.DoubleClick += notifyIcon_DoubleClick;
notifyIcon.Click += notifyIcon_Click;
notifyIcon.MouseUp += notifyIcon_MouseUp;
// Create ContextMenu
contextMenu = new ContextMenuStrip();
contextMenu.Closing += contextMenu_Closing;
// Exit item
menuItemExit = new ToolStripMenuItem
{
Text = Cultures.Resources.Exit,
Image = Cultures.Resources.close
};
menuItemExit.Click += menuItemExit_Click;
// Restore item
menuItemRestore = new ToolStripMenuItem
{
Text = Cultures.Resources.Restore,
Image = Cultures.Resources.restore1
};
menuItemRestore.Click += menuItemRestore_Click;
// Active or inactive log
menuItemActive = new ToolStripMenuItem
{
Text = Cultures.Resources.On,
Image = Cultures.Resources.green,
Checked = true
};
menuItemActive.Click += menuItemActive_Click;
menuItemActive.CheckStateChanged += menuItemActive_CheckStateChanged;
// Order of appearance of ContextMenu items
contextMenu.Items.Add(menuItemActive);
contextMenu.Items.Add("-");
contextMenu.Items.Add(menuItemRestore);
contextMenu.Items.Add(menuItemExit);
notifyIcon.ContextMenuStrip = contextMenu;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Any idea on how to keep both icons for WPF?
Well, Its not possible to show forms in taskbar which is in hidden state. Still you can forcefully minimized the form. try below modified code :
private void MainWindow_OnStateChanged(object sender, EventArgs e)
{
if (WindowState != WindowState.Minimized) return;
this.ShowInTaskbar = true;
if (notifyIcon != null)
notifyIcon.ShowBalloonTip(2000);
this.WindowState = FormWindowState.Minimized;
}
I'm trying to create a dialog where the user gets to choose between some buttons, but the problem I'm experiencing now is that when the user closes the window (not choosing a button but using the x on the top right corner), the application shows the message but after that it crashes. Does anybody know what I am doing wrong here?
MainWindow.xaml.cs
public partial class MainWindow : Window
{
string[,] suppliers = new string[3,2] {{"xxx", "xxx"}, {"yyy", "yyy"}, {"zzz" , "zzz"}};
public MainWindow()
{
InitializeComponent();
ButtonPrompt buttonPrompt = new ButtonPrompt(suppliers, "Select supplier.");
while (buttonPrompt.ShowDialog() != true)
{
MessageBox.Show("Please choose one of the suppliers!");
}
}
}
ButtonPrompt.xaml.cs:
public partial class ButtonPrompt : Window
{
public ButtonPrompt(string[,] buttons, string question)
{
InitializeComponent();
buttonStack.Children.Clear();
TextBlock questionBlock = new TextBlock();
questionBlock.Text = question;
buttonStack.Children.Add(questionBlock);
for (int i = 0; i < buttons.GetLength(0); i++)
{
Button inputButton = new Button();
inputButton.Name = buttons[i, 0];
inputButton.Content = buttons[i, 1];
inputButton.Width = 200;
inputButton.Height = 60;
inputButton.Click += inputButton_Click;
buttonStack.Children.Add(inputButton);
if (i == 0)
{
inputButton.Focus();
}
}
}
private void inputButton_Click(object sender, RoutedEventArgs e)
{
Button inputButton = (Button)sender;
this.DialogResult = true;
}
private void Window_Closed(object sender, EventArgs e)
{
this.DialogResult = false;
}
}
Thanks in advance!
The buttonPrompt.ShowDialog() returns true when the Window is closed.
Documentation says about the Window_Closed
Once this event is raised, a window cannot be prevented from closing.
This means that you cannot set the DialogResult because it's already true and your while doesn't work.
You have three possibilities:
Override the OnClosing method like in How to override default window close operation? to prevent the window is closed from the GUI Button.
(My favourite) Override the OnClosing event like in http://msdn.microsoft.com/it-it/library/system.windows.window.closing.aspx checking for your own conditions and adding this.DialogResult = false
Hide the close button of you Dialog Window from the XAML setting WindowStyle=None
Update: On the other side, put your while check out of your Main Window initialization, try with the Loaded handler so you're sure your Main component doesn't have troubles while coming up.
I use MDI in MainForm.cs
public Le_MainForm()
{
InitializeComponent();
this.IsMdiContainer = true;
this.Name = "MainUSER";
}
private void barButtonItem_ListeOrdres_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Close_AllForm();
Liste_Ordres f_Liste = new Liste_Ordres();
f_Liste.MdiParent = this;
f_Liste.Show();
}
private void barButtonItem_CreatOrdreAller_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Close_AllForm();
Program.AllerRetour = "Ordre Aller";
Fiche_Ordre f_Fiche = new Fiche_Ordre();
f_Fiche.MdiParent = this;
f_Fiche.Show();
}
the question now, when I am in other form Ex.:Liste_Ordres.cs or Fiche_Ordre.cs how can i redirect from Fiche_Ordre.cs into Liste_Ordres.cs and vice versa without loosing MDI ?
When I'm in Fiche_Ordres.cs to go to Liste_Ordres.cs I use:
private void simpleButton_Annluer_Click_1(object sender, EventArgs e)
{
Liste_Ordres f_Liste = new Liste_Ordres();
f_Liste.Show();
this.Close();
}
But as you can see I lose the MDI, that mean when I click the menu on MainForm, the Liste_Ordres form will disappear.
as you can see in this Video that when i redirect From Liste to fiche, and then maximize the window i lose the menu that mean i lose Mdi.
You just need to set the MdiParent again:
f_Liste.MdiParent = this.MdiParent;
Can i know how can i make a popup bubble message in my application coded in C#.
Like example, when i start my application, it'll popup saying "Welcome to UbuntuSE App".
And yea, The popup is not the message box popup, it's the popup in the traymenu.
Something similar to this:
PS,
If i'm not wrong, this is called Balloon Tooltips. But how can i use this in my codes.
If you're using Winforms you have the NotifyIcon class. This object has a ShowBalloonTip method which will show a balloon tip:
var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
you must be looking for the Notify Icon Control
another CodeProject Example
here is a full example in MSDN
You can use the NotifyIcon control that's part of .NET 2.0 System.Windows.Forms.
Check : Using the NotifyIcon control
From the msdn,
NotifyIcon : Specifies a component that creates an
icon in the notification area. This
class cannot be inherited.
NotifyIcon.BalloonTipIcon
You have to set the property "icon" or it won't pop up
NotifyIcon ballon = new NotifyIcon();
ballon.Icon = SystemIcons.Application;//or any icon you like
ballon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace ShowToolTip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btBallonToolTip_Click(object sender, EventArgs e)
{
ShowBalloonTip();
this.Hide();
}
private void ShowBalloonTip()
{
Container bpcomponents = new Container();
ContextMenu contextMenu1 = new ContextMenu();
MenuItem runMenu = new MenuItem();
runMenu.Index = 1;
runMenu.Text = "Run...";
runMenu.Click += new EventHandler(runMenu_Click);
MenuItem breakMenu = new MenuItem();
breakMenu.Index = 2;
breakMenu.Text = "-------------";
MenuItem exitMenu = new MenuItem();
exitMenu.Index = 3;
exitMenu.Text = "E&xit";
exitMenu.Click += new EventHandler(exitMenu_Click);
// Initialize contextMenu1
contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu });
// Initialize menuItem1
this.ClientSize = new System.Drawing.Size(0, 0);
this.Text = "Ballon Tootip Example";
// Create the NotifyIcon.
NotifyIcon notifyIcon = new NotifyIcon(bpcomponents);
// The Icon property sets the icon that will appear
// in the systray for this application.
string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + #"\setup-icon.ico";
notifyIcon.Icon = new Icon(iconPath);
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon.ContextMenu = contextMenu1;
notifyIcon.Visible = true;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon.Text = "Morgan Tech Space BallonTip Running...";
notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running...";
notifyIcon.BalloonTipTitle = "Morgan Tech Space";
notifyIcon.ShowBalloonTip(1000);
}
void exitMenu_Click(object sender, EventArgs e)
{
this.Close();
}
void runMenu_Click(object sender, EventArgs e)
{
MessageBox.Show("BallonTip is Running....");
}
}
}
Thanks for the info!
Made something like this and worked!
private void NotifyBaloon(string text, string tooltip, string title, bool show)
{
notifyIconMain.Text = text;
notifyIconMain.BalloonTipText = tooltip;
notifyIconMain.BalloonTipTitle = title;
if (show)
notifyIconMain.ShowBalloonTip(1000);
}