Showing posts with label WinForms. Show all posts
Showing posts with label WinForms. Show all posts

C# How to change UI control from other thread (WinForms and WPF)

WinForms:
public delegate void updateTextBoxDelegate(String textBoxString);  
public updateTextBoxDelegate updateTextBox; 

void updateTextBox1(string str ) { textBox1.Text = str1; } 

void display( string strItem ) 
{
         Form1.Invoke( Form1.updateTextBox, strItem ); 
}


WPF:
tempWindow.Dispatcher.BeginInvoke(new Action(delegate()
                    {
tempWindow.ChangeControlMethod();
                    }));

c# scroll panel with picturebox by dragging mouse


private Point _StartPoint;
void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
  if (e.Button == MouseButtons.Left)
    _StartPoint = e.Location;
}
void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
  if (e.Button == MouseButtons.Left) {
    Point changePoint = new Point(e.Location.X - _StartPoint.X, 
                                  e.Location.Y - _StartPoint.Y);
    panel1.AutoScrollPosition = new Point(-panel1.AutoScrollPosition.X - changePoint.X,
                                          -panel1.AutoScrollPosition.Y - changePoint.Y);
  }
}
A Meaning (Prod. By Joel Johnston) by Hi-Rez on Grooveshark