Search This Blog

Friday, October 31, 2008

Reduce in Flicker in Rich Text Box

From forums.microsoft.com

MSFT forgot to add the BeginUpdate and EndUpdate methods to RTB. Here's a sample workaround that uses SendMessage():

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.Load += new System.EventHandler(this.Form1_Load);
this.button1.Click += new System.EventHandler(this.button1_Click);
}
private void Form1_Load(object sender, EventArgs e) {
for (int ix = 0; ix < 200; ++ix) richTextBox1.Text += "nobugz waz here\r\n";
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private extern static IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

private void button1_Click(object sender, EventArgs e) {
richTextBox1.Focus();
SendMessage(richTextBox1.Handle, 0xb, (IntPtr)0, IntPtr.Zero);
for (; ; ) {
int pos = richTextBox1.Find("bugz", richTextBox1.SelectionStart + 1, RichTextBoxFinds.None);
if (pos < 0) break;
richTextBox1.SelectionStart = pos;
richTextBox1.SelectionLength = 4;
richTextBox1.SelectionBackColor = Color.Aqua;
}
richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 0;
SendMessage(richTextBox1.Handle, 0xb, (IntPtr)1, IntPtr.Zero);
richTextBox1.Invalidate();
}
}
}

STop Form Flickr on XP and Vista

Use under documented Style from MSDN forum

Add this to form

protected override CreateParams CreateParams
{
get
{ //WS_EX_COMPOSITED XP AND Vista Only
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}

Saturday, October 25, 2008

FlowLayoutPanel FLickers when Controls added

Discussion Thread

Potential Solution:
Add the following code to add being added.

Add following code to Class Constructor

SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

protected override CreateParams CreateParams {
get {
// Turn on the WS_EX_TRANSPARENT style
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}

example:

public PhotoAccount(Account acct)
{ _acct = acct;
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

RefreshAccountSpace();
txtAccount.MouseClick += new MouseEventHandler(txtAccount_MouseClick);
txtAccount.MouseDoubleClick += new MouseEventHandler(txtAccount_MouseDoubleClick);
}

protected override CreateParams CreateParams
{
get
{
// Turn on the WS_EX_TRANSPARENT style
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}

Tuesday, October 21, 2008

VB6 IDE Make/Build menu disabled

Problem:

VB6 IDE can get into a state when the Make XXXX menu option under the File Menu is disabled.

Solution:

Right click on your toolbar, goto Customize and reset toolbars.

Wednesday, October 15, 2008

FireFly Theme - Ballad of Serenity

Download from here.

C# - Create Custom Exception

How to create a custom exception message in C#

Sample from http://www.blackwasp.co.uk/CSharpThrowingExceptions.aspx


using System;

namespace BlackWasp
{
class TestApp
{
static void Main(string[] args)
{
// Check that a parameter was provided
if (args.Length == 0)
{
throw new ArgumentException("A start-up parameter is required.");
}

Console.WriteLine("{0} argument(s) provided", args.Length);
}
}
}

C# Equivalent of VB's IsNumeric()

C# calls Equivalent of VB's IsNumeric() from CodeProject

Int32.TryParse() Method

int result;
if (int.TryParse("123", out result))
{
Debug.WriteLine("Valid integer: " + result);
}
else
{
Debug.WriteLine("Not a valid integer");
}

// throws ArgumentNullExceptionint
result1 = Int32.Parse(null);

// doesn't throw an exception, returns 0
int result2 = Convert.ToInt32(null);