[Solved] To clear loaded images in a picturebox-c#

Your code has many issues. The one you are looking for is that you don’t clear the alist before loading new file names. So insert: alist.Clear(); before //Get Each files And also filelength = alist.Count; after the loop. No need to count while adding! Also note that ArrayList is pretty much depracated and you should … Read more

[Solved] Accessing Forms data from another form

First of all you have to create an instance of Form2. namespace WindowsFormsApplication1 { public partial class Form1 : Form { private Form2 form2; public Form1() { InitializeComponent(); form2 = new Form2(); } private void button1_Click(object sender, EventArgs e) { String value1 = File.ReadAllText(textBox1.Text); foreach (string line in value1.Split(‘\n’)) { form2.listBox1.Items.Add(line); } } } } … Read more

[Solved] Cross-thread operation not valid: Control ‘Form1’ accessed from a thread other than the thread it was created on

In this case, write invoke operation inside of method. Then you can access both from control’s thread and other threads. delegate IntPtr GetWindowHandleDelegate(); private IntPtr GetWindowHandle() { if (this.InvokeRequired) { return (IntPtr)this.Invoke((GetWindowHandleDelegate)delegate() { return GetWindowHandle(); }); } return this.Handle; } or, if you want to avoid delegate hell, you could write in more few code … Read more

[Solved] Write text file and open at same time

Is this what you are looking for? FileStream currentFileStream = null;//EDIT string tempFilePath = Directory.GetCurrentDirectory() + “\\TEMP.txt”; if (!File.Exists(tempFilePath)) { currentFileStream = File.Create(tempFilePath);//creates temp text file currentFileStream.Close();//frees the file for editing/reading }//if file does not already exist File.WriteAllText(tempFilePath, textbox1.Text);//overwrites all text in temp file //Inside your exit function: if(File.Exists(tempFilePath)) File.Delete(tempFilePath);//delete temp file 2 solved Write … Read more

[Solved] C# Method makes forms dynamically via string

Here’s a simple example using the Reflection approach: private void button1_Click(object sender, EventArgs e) { Form f2 = TryGetFormByName(“Form2”); if (f2 != null) { f2.Show(); } } public Form TryGetFormByName(string formName) { var formType = System.Reflection.Assembly.GetExecutingAssembly().GetTypes() .Where(T => (T.BaseType == typeof(Form)) && (T.Name == formName)) .FirstOrDefault(); return formType == null ? null : (Form)Activator.CreateInstance(formType); } … Read more

[Solved] How can i sort array: string[]?

You can try the following string[] strarr = new string[] { @”c:\temp\newimages\Changed_Resolution_By_10\SecondProcess_-Width = 502 Height = 502\animated502x502.gif”, @”c:\temp\newimages\Changed_Resolution_By_10\SecondProcess_-Width = 492 Height = 492\animated492x492.gif”, @”c:\temp\newimages\Changed_Resolution_By_10\SecondProcess_-Width = 2 Height = 2\animated2x2.gif” }; IEnumerable<string> strTest = strarr.OrderByDescending(p => p.Substring(p.IndexOf(“x”), p.Length – p.IndexOf(“.”))); solved How can i sort array: string[]?

[Solved] Get Difference of 2 Paths [duplicate]

If Path actually contains double slashes (which usually doesn’t happen): Replace \\ with \ in path1 Replace path1 with Empty String in path2 string diff = path2.Replace(path1.Replace(@”\\”, @”\”), “”); Otherwise: string diff = path2.Replace(path1, “”); 9 solved Get Difference of 2 Paths [duplicate]

[Solved] how to add strings together?

You have several issues here: First of all, your string cu is declared inside the if scope. It will not exist outside that scope. If you need to use it outside the scope of the if, declare it outside. Second, math operations cannot be applied to strings. Why are you casting your numeric values to … Read more

[Solved] Is there a way to realtime detect if there’s new record in database?

Don’t worry about the performance of polling. With a suitable INDEX, MySQL can handle 100 polls/second — regardless of dataset size. Let’s see SHOW CREATE TABLE and the tentative SELECT to perform the “poll”; I may have further tips. Also, let’s see the admin’s query that needs to ‘trigger’ the workers into action. Surely the … Read more