When I try to start my form, it flashes like it never opened.
I have already looked into my code and there is nothing wrong
Here's my code:
public partial class Initialization : Form
{
public Initialization()
{
InitializeComponent();
}
private async Task Wait1(int Milliseconds)
{
await Task.Delay(Milliseconds);
}
private async void Wait(int Millisecondsdew)
{
Wait1(Millisecondsdew);
}
private void Initialization_Load(object sender, EventArgs e)
{
MessageBox.Show("Initialization");
///Setup Stuff///
ShowIcon = false;
ControlBox = false;
FormBorderStyle = FormBorderStyle.FixedDialog;
Text = "";
/// Start Initializing///
richTextBox1.Text = "Initializing....";
Wait(1000);
if (File.Exists(#"C:\Program Files (x86)\Lazy Tools\AdditionalFiles.exe"))
{
richTextBox1.Text = "Initializing.... \n Software Installers 1 Exists";
Wait(1000);
if (File.Exists(#"C:\Program Files (x86)\Lazy Tools\SoftwareInstallers2.exe"))
{
richTextBox1.Text = richTextBox1.Text + "\n Software Installers 2 Exists";
Wait(1000);
}
else
{
MessageBox.Show("Please reinstall software store, \n Software Installers 2 is missing");
}
}
else
{
MessageBox.Show("Please reinstall software store, \n Software Installers 1 is missing");
}
}
}
The async works fine on my first form, but this is the second form. When I call up the second form, it flashes and it like never opened.
Apparently, setting the ControlBox property to false and then setting the Text property to an empty string after the form has loaded causes the form to close (which seems like a bug).
Code to reproduce the issue:
// Using other events like `Form_Shown` or even a `Button_Click` still has the same behavior
private void Form1_Load(object sender, EventArgs e)
{
this.ControlBox = false;
this.Text = "";
}
As a workaround, you may, instead, set the FormBorderStyle property to FormBorderStyle.None:
this.FormBorderStyle = FormBorderStyle.None;
..which will have a similar effect to what you're trying to achieve. This is actually the standard way to hide the title bar.
If you don't want to hide the border or you actually want to use the ControlBox and the Text properties, you can do any of the following:
Set those two properties at design-time. Or...
Move those two lines to the constructor of the form:
public Initialization()
{
InitializeComponent();
this.ControlBox = false;
this.Text = "";
}
Or make sure to set the Text property before the ControlBox property:
private void Initialization_Load(object sender, EventArgs e)
{
this.Text = "";
this.ControlBox = false;
}
Related
So i have that aplication:
Menu Picture
and when i press the button "Terminar sessão" it's supposed to log out (and its works)
but when i went back to login the menu does not close!
Login Picture after log out
I am using nested form, the form ends session is closing but not the menu.
This is my menu.cs:
private Form activeForm = null;
private void openChildForm(Form childForm)
{
if (activeForm != null) activeForm.Close();
activeForm = childForm;
childForm.TopLevel = false;
childForm.FormBorderStyle = FormBorderStyle.None;
childForm.Dock = DockStyle.Fill;
panelChildForm.Controls.Add(childForm);
panelChildForm.Tag = childForm;
childForm.BringToFront();
childForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
panel1.Visible = false;
openChildForm(new Transferências());
Slidepanel.Height = (button2.Height - 15);
Slidepanel.Top = (button2.Top + 10);
}
and on "Transferências" form i have it:
private void Sessao_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Tem a certeza que deseja terminar sessão?", "Terminar Sessão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.Hide();
Login login = new Login();
login.ShowDialog();
}
}
i already tried Menu.Close(); but it does not work
With the amount of information you provide, it is quite hard to tell what the problem might be. Did you try to debug it to verify that your program actually tries to execute Menu.Close()?
If you show your code people might be able to help you more.
I have a notify icon in my Winforms form and it seems that when any kind of event happens the tray icon is duplicated.
I have debugged one of the issues, being that it is duplicated when the dialog box is closed after using it.
It happens in debug and when released.
The other issue it with a timer that runs method.
I cannot see why this happens. My timer ran 60 times last night and each time it has four methods to run and there were hundreds of icons in the tray.
My code is as follows:
public Form1()
{
InitializeComponent();
notifyIcon1.BalloonTipText = "Mappi CSV Manager is running.";
notifyIcon1.BalloonTipTitle = "Mappi CSV Manager";
notifyIcon1.Text = "Mappi CSV Manager";
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
ShowIcon = false;
ShowInTaskbar = false;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(1000);
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
ShowInTaskbar = true;
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
// Call Dispose to remove the icon out of notification area of Taskbar.
notifyIcon1.Dispose();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (CloseCancel() == false)
{
e.Cancel = true;
};
}
//When closing the form
public static bool CloseCancel()
{
const string message = "If you close the program, no files will be generated!";
const string caption = "Stop!";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
return true;
else
return false;
}
//Set new value for timer
private void UdTimerValue_ValueChanged(object sender, EventArgs e)
{
timer1.Interval = Convert.ToInt32(udTimerValue.Value) * 60000;
}
//Start generating CSV's
private void Timer1_Tick(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
if (AutoGenerateEnabled)
{
richLogWindow.AppendText("CSV Created at: " + DateTime.Now + "\r\n");
var startdate = "";
if(DateTime.Now.Hour == 1)
{
richLogWindow.Clear();
startdate = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
CSVGenerator.GenerateCSV(startdate, this);
}
else
{
startdate = DateTime.Today.ToString("yyyy-MM-dd");
CSVGenerator.GenerateCSV(startdate, this);
}
}
else
{
return;
}
}
}
Why is this code producing another tray icon every time a button is clicked or an event happens.
TIA
I found the error. I have put RichTextBoxAppend.AddNewText("test me", new Form1()); the new form was created each time a process was run. I am an idiot!
I'm trying to display a website in a form and automatically reload the website to see if a certain text is present. I'm doing this in a C# form and try to call a while with an button. This is the code I made:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnStartLoop_Click(object sender, EventArgs e)
{
lblStatusLoop.Text = "Status loop: Started";
lblStatusLoop.ForeColor = System.Drawing.Color.Green;
int i = 0;
while (i < 10)
{
Browser.Navigate("www.google.com");
Browser.DocumentCompleted += Browser_DocumentCompleted;
Thread.Sleep(5000);
i++;
}
}
void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string ZoekText = txtSearchbox.Text.ToString();
if (Browser.DocumentText.Contains(ZoekText))
{
lblSearchResult.Text = "Text found";
}
else
{
lblSearchResult.Text = "Text not found";
}
}
}
As soon as I push the button the appliction freezes and I have to force quit it. I've done some research on google and suggestions were to wait for the document to complete loading but it has no effect.
I don't have much programming experience and do not have someone to fall back on so I hope someone here can point me into right direction.
I am trying to get my application to minimize to the notification area and that part is working. The problem is, when I double click it, it is not showing the window again.
This is what I'm doing, I hope it's something simple I'm doing wrong:
public partial class Main : Form
{
public Main()
{
InitializeComponent();
CreateNotifyIcon();
}
private void CreateNotifyIcon()
{
mynotifyicon.BalloonTipIcon = ToolTipIcon.Info;
mynotifyicon.BalloonTipText = "[Balloon Text when Minimized]";
mynotifyicon.BalloonTipTitle = "[Balloon Title when Minimized]";
mynotifyicon.Icon = Resources.lightning;
mynotifyicon.Text = "[Message shown when hovering over tray icon]";
}
private void MainLoad(object sender, EventArgs e)
{
Resize += MainResize;
MouseDoubleClick += MainMouseDoubleClick;
}
private void MainResize(object sender, EventArgs e)
{
try
{
if (FormWindowState.Minimized == WindowState)
{
mynotifyicon.Visible = true;
mynotifyicon.ShowBalloonTip(3000);
ShowInTaskbar = false;
Hide();
}
else if (FormWindowState.Normal == WindowState)
{
mynotifyicon.Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
private void MainMouseDoubleClick(object sender, MouseEventArgs e)
{
try
{
Show();
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
mynotifyicon.Visible = false;
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
Something I forgot to mention was I put a debug stop on MainMouseDoubleClick and it's never hitting that point.
Thanks for the help!
** EDIT **
I changed the double click to have a try/catch and it's not being reached at all. Not even to the try.
You need to add the click event to the notifyicon. At the moment you are registering the handler on the form.
mynotifyicon.MouseDoubleClick += MainMouseDoubleClick;
Attach the MouseDoubleClick event at the end of CreateNotifyIcon:
mynotifyicon.MouseDoubleClick += MainMouseDoubleClick;
I would recommend renaming the event handler MainMouseDoubleClick to something more appropriate and unregistering it from the form's double click event.
I have used this and its working :
this.WindowState = FormWindowState.Normal;
this.Activate();
I am working on a program to manage a minecraft server with a local UI as well as a remote interface. I have a button on a ribbon bar that will enable or disable the remote interface and a textbox for inputting the port. Currently, I disable the textbox when the networking is enabled, but, disabling does not re-enable the textbox after I set it to true again (and setting a breakpoint reveals it to still be false).
private void NetToggleChecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = false;
if (ButtonPressedByUser) {
var result = MessageBox.Show("Are you sure you want to enable networking with the current settings?" +
" If not properly configured, it may be possible for an attacker to enter your server.",
"Simple Bukkit Wrapper", MessageBoxButton.YesNo, MessageBoxImage.Warning,
MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "true";
int port;
if (!int.TryParse(Config.NetConf["port"], out port)) {
MessageBox.Show("Port could not be parsed (is it a number?)");
ButtonPressedByUser = false;
NetworkToggle.IsChecked = false;
ButtonPressedByUser = true;
return;
}
Net.Listener.StartListening(port);
}
private void NetworkToggleUnchecked(object sender, RoutedEventArgs e) {
portTextBox.IsEnabled = true;
if (ButtonPressedByUser) {
var result =
MessageBox.Show("Are you sure you wish to disable all networking to your server? It will " +
"be impossible to connect to it remotely and any existing connections will be closed.",
"", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (result == MessageBoxResult.No) {
ButtonPressedByUser = false;
NetworkToggle.IsChecked = true;
ButtonPressedByUser = true;
return;
}
}
Config.NetConf["enabled"] = "false";
Net.Listener.StopListening();
}
Thank you for any help resolving why the textbox will not enable again.
Old Question but i kept coming across it while searching for an answer so figured i'd post an answer anyways. There is a bug in the ribbonTextbox control that results in isenabled always being false if there is no command associated. There are 2 ways round this from what i have found:
1: Create a new control based on the ribbontextbox and override the isenabledcore property to always return true. As shown here Cannot set RibbonTextBox isEnable to False
2: Create a dummy command and associate it with the control
public static readonly ICommand DummyCommand = new RoutedCommand("Dummy", typeof(Control));
public static void Dummy(Object sender, ExecutedRoutedEventArgs e)
{
// Do nothing its a dummy command
}
public static void CanDummy(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
as described in a comment in this link http://blogs.msdn.com/b/wpf/archive/2010/10/21/wpf-ribbon-october-2010-update-details.aspx .
AS i said probably no help to the original poster but i kept coming across it while looking for an answer so it may save someone else a few minutes of googling time.