Windows Form is Really Laggy - c#

I have a windows Form Project that runs smoothly and fine on framework 4.5.1
But yet I have a project on framework 2.0 that is so laggy even after i changed the target framework to 4.5.1
so why is one project slow and the other is normal?
Update :
here is the Main From
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show(" ", "About US");
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Add AddForm = new Add();
AddForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Search SearchForm = new Search();
SearchForm.Show();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
and here is its design
Update 2 :
Form "Add.cs" that dose not lag .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class Add : Form
{
public Add()
{
InitializeComponent();
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
AddBook AddBookForm = new AddBook();
AddBookForm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
MainForm mainForm = new MainForm();
mainForm.Show();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void publisherButt_Click(object sender, EventArgs e)
{
this.Close();
AddPublishercs AddPublisherForm = new AddPublishercs();
AddPublisherForm.Show();
}
private void authorButt_Click(object sender, EventArgs e)
{
//this.Close();
//AddAuthor AddAuthorForm = new AddAuthor();
//AddAuthorForm.Show();
}
private void Add_Load(object sender, EventArgs e)
{
}
}
}

Try removing the panel1 paint eventhandler. This will get called (even tho its empty) ever time the panel has to draw itself, which is all the time in a designer environment.
Remove this code:
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
There will also be code inside of InitializeComponent() similar to this
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1);
Remove it as well. Clean and rebuild solution. Close all designer windows. Try again.

Related

CefSharp Set Object reference for buttons C#?

WinForms:
I am new to Cefsharp and C# , just wrote a freeware 'Kid Safe Browser' in VS vb.net in visual basic , but IE11 is too limited .
I am getting "Object reference not set" for all Buttons . How to fix this ? For example:
How do I set an Object Reference for Chrome Load and Navigate Back Forward Refresh etc. ?
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=CefSharpBrowser01
StackTrace:
at CefSharpBrowser01.SafeBrowser.GotoBtn_Click(Object sender, EventArgs e) in
C:\Users\vmars\source\repos\CefSharpBrowser01\Form1.cs:line 64
using CefSharp.WinForms;
using CefSharp.WinForms.Internals;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using cef;
namespace CefSharpBrowser01
{
public partial class SafeBrowser : Form
{
public SafeBrowser()
{
InitializeComponent();
}
ChromiumWebBrowser chrome;
private void SafeBrowser_Load(object sender, EventArgs e)
{
CefSettings settings = new CefSettings();
//Initialize;
Cef.Initialize(settings);
AddressTxt.Text = "https://www.google.com";
chrome = new ChromiumWebBrowser(AddressTxt.Text);
this.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
chrome.AddressChanged += Chrome_AddressChanged;
}
private void Chrome_AddressChanged(object sender, AddressChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
AddressTxt.Text = e.Address;
}));
}
private void BackBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoBack)
chrome.Back();
}
private void ForwardBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoForward)
chrome.Forward();
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
chrome.Refresh();
}
private void GotoBtn_Click(object sender, EventArgs e)
{
chrome.Load(AddressTxt.Text);
}
}
}
Thanks for your Help...
Your problem really isn't anything to do with CefSharp, it's that you haven't created an instance of a class that you are trying to reference. Refactoring your code like I've suggested in the comments so the class is actually instantiated.
namespace CefSharpBrowser01
{
public partial class SafeBrowser : Form
{
public SafeBrowser()
{
InitializeComponent();
CefSettings settings = new CefSettings();
//Initialize;
Cef.Initialize(settings);
AddressTxt.Text = "https://www.google.com";
chrome = new ChromiumWebBrowser(AddressTxt.Text);
this.Controls.Add(chrome);
chrome.Dock = DockStyle.Fill;
chrome.AddressChanged += Chrome_AddressChanged;
}
ChromiumWebBrowser chrome;
private void Chrome_AddressChanged(object sender, AddressChangedEventArgs e)
{
this.Invoke(new MethodInvoker(() =>
{
AddressTxt.Text = e.Address;
}));
}
private void BackBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoBack)
chrome.Back();
}
private void ForwardBtn_Click(object sender, EventArgs e)
{
if (chrome.CanGoForward)
chrome.Forward();
}
private void RefreshBtn_Click(object sender, EventArgs e)
{
chrome.Refresh();
}
private void GotoBtn_Click(object sender, EventArgs e)
{
chrome.Load(AddressTxt.Text);
}
}
}

C# Winforms change label based on running process

I have a dotnet 2.0 app in C# that I have developed in Visual Studio 2008, it's pretty simple:
I would like to change the label name currently called "label1" to "Running" or "Stopped" when my process loop.exe is running or stopped.
When I press start, it will run loop.exe and the stop button will obviously stop it.
I've read a lot of topic on C# Winforms but I cannot get this working and I have no idea what do to now. I think that I need to add a backgroundworker but I don't know how to check the process and update the label programmatically.
Here's my clean/current code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace APP_NAME
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process.Start("taskkill", "/F /IM loop.exe");
Process.Start("taskkill", "/F /IM azcopy.exe");
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Process.Start("notepad.exe", #"C:\ProgramData\APP_NAME\settings\settings.xml");
}
private void button4_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", #"C:\ProgramData\APP_NAME\logs");
}
}
}
I hope I made myself clear, thank you.
You can update the text shown by a label by accessing it's Text property. So, change your method like:
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
}
//hi
//Do this to see the label value changes in real time in the window
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
lable1.Refresh();
}

By pressing a button i want to show the user all the data inserted to the boxes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Apostolh_Texnikou
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void GN_TextChanged(object sender, EventArgs e)
{
}
private void CP_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
I want the user to click in the ready button and a window to pop out.
In the window the user must be able to copy the text.
I found how to make a pop window but its just a window which doesn't allow
copy paste. thank you in advance
You might want to look into a more complex type of dialog box. Perhaps one with a textbox? This will require launching another form. (see how to display textBox control in MessageBox?)

WebCam_Capture notfound

I'm new and I have a problem with a class.
I have ever that problem " An unhandled exception of type 'System.IO.FileNotFoundException' occurred in WinFormCharpWebCam.exe"
But I added the refrence to my code.
Someone Can help me ?
Thank's
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using WebCam_Capture;
namespace WinFormCharpWebCam
{
//Design by Pongsakorn Poosankam
public partial class mainWinForm : Form
{
public mainWinForm()
{
InitializeComponent();
}
WebCam webcam;
private void mainWinForm_Load(object sender, EventArgs e)
{
webcam = new WebCam();
// webcam.InitializeWebCam(ref imgVideo);
}
private void bntStart_Click(object sender, EventArgs e)
{
webcam.Start();
}
private void bntStop_Click(object sender, EventArgs e)
{
webcam.Stop();
}
private void bntContinue_Click(object sender, EventArgs e)
{
webcam.Continue();
}
private void bntCapture_Click(object sender, EventArgs e)
{
imgCapture.Image = imgVideo.Image;
}
private void bntSave_Click(object sender, EventArgs e)
{
Helper.SaveImageCapture(imgCapture.Image);
}
private void bntVideoFormat_Click(object sender, EventArgs e)
{
webcam.ResolutionSetting();
}
private void bntVideoSource_Click(object sender, EventArgs e)
{
webcam.AdvanceSetting();
}
}
}

C# Windows Forms - Textbox in Form2 into List item Form1 [duplicate]

This question already has answers here:
Send values from one form to another form
(20 answers)
Closed 7 years ago.
I am having a problem adding text from my Form 2, to the List item in Form 1. Could anyone help please, Sorry if it's a bit jumbled, I'm new with coding :) What I am trying to achieve is a to-do list application, in the 2nd form, text should be entered in a text box - when the user clicks enter, this text should be entered into the list item.
Another question is, in this case would I be better using a list item or a list box?
Here is the code:
FORM 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ToDoList
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void button2_Click(object sender, EventArgs e, string tbtext)
{
//Form1 form1 = new Form1();
//form1.listBox1.Items.Add(tbtext);
}
public void button1_Click(object sender, EventArgs e)
{
this.Close();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(textBox1.Text);
Form1 f1 = new Form1();
f1.listView1.Items.Add(item);
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
}
}
FORM 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ToDoList
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void filesToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
public void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void button2_Click(object sender, EventArgs e)
{
}
public void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void F1Button1_Click(object sender, EventArgs e)
{
}
private void tB1_TextChanged(object sender, EventArgs e)
{
}
public void listView1_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
}
}
You create different object Form1, and the object is destroyd after you quit button2_Click. Is it local variable.
You need to create the datasource for your TODO list and propaget it to both forms, for example by method Set DataSource. Then you have one object accesible by
both forms.

Categories