Posts

Showing posts with the label gui

WPF DataGrid change cell value based on underlying data object

XAML <Window x:Class=" DataGridCellBackground.MainWindow " xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml " xmlns:DataGridCellBackground=" clr-namespace:DataGridCellBackground " Title=" MainWindow " Height=" 350 " Width=" 525 " DataContext=" {Binding RelativeSource={RelativeSource Self}} "> <Window.Resources> <DataGridCellBackground:DataGridCellValueConverter x:Key=" dataGridCellValueConverter "/> </Window.Resources> <Grid> <DataGrid ItemsSource=" {Binding Data} " Width=" 400 " Height=" 200 " CanUserAddRows=" False "> <DataGrid.CellStyle> <Style TargetType=" {x:Type DataGridCell} "> <Setter Property=" Template "> <Setter.Value...

WPF Toggle button group

<StackPanel> <RadioButton Content=" Left " Style=" {StaticResource {x:Type ToggleButton}} " /> <RadioButton Content=" Right " tyle=" {StaticResource {x:Type ToggleButton}} " /> </StackPanel>

WPF DataGrid change cell style based on underlying data object

XAML < Window x : Class = "DataGridCellBackground.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns : x = "http://schemas.microsoft.com/winfx/2006/xaml" xmlns : DataGridCellBackground = "clr-namespace:DataGridCellBackground" Title = "MainWindow" Height = "350" Width = "525" DataContext = "{Binding RelativeSource={RelativeSource Self}}" > < Window.Resources > < DataGridCellBackground : DataGridCellBackgroundConverter x : Key = "dataGridCellBackgroundConverter" /> </ Window.Resources > < Grid > < DataGrid ItemsSource = "{Binding Data}" Width = "400" Height = "200" > < DataGrid.CellStyle > < Style TargetType = "{x:Type DataGridCell}" > < Setter Property = "Background" > ...

Disable C# Form resizing

form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

C# Updating GUI from different thread

void MyEventHandler( object sender, EventArgs e) { if (this.InvokeRequired) { this.Invoke( new EventHandler(MyEventHandler), new object [] { sender, e } ); } else { //update GUI here } } void MyEventHandler( object sender, MyEventArgs e) { if (this.InvokeRequired) { this.BeginInvoke( new EventHandler<MyEventArgs>(MyEventHandler), new object [] { sender, e }); } else { //update GUI here } }

Events in C#

public class Messenger { public delegate void MessageEventHandler( object source, MessageEvent e); public event MessageEventHandler changed; public void Run() { fireMessageEvent("Message"); } private void fireMessageEvent(string text) { log.Info(text); if (changed != null ) { changed(this, new MessageEvent(text)); } } } public class MessageEvent : EventArgs { private readonly string message; public MessageEvent(string message) { this.message = message; } public string Message { get { return this.message; } } } public class Client { Messenger messenger = new Messenger(); public Client(){ messenger.changed += new Messenger.MessengerEventHandler(messenger_changed); } void messenger_changed( object source, MessageEvent e) { Console.WriteLine(e.Message); } }

Autoscroll in C# RichTextBox

using System.Runtime.InteropServices; #region WinAPI //WinAPI-Declaration for SendMessage [DllImport(" user32.dll ")] public static extern IntPtr SendMessage( IntPtr window, int message, int wparam, int lparam); const int WM_VSCROLL = 0x115; const int SB_BOTTOM = 7; #endregion SendMessage(richTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);