September 20, 2007
@ 12:12 PM

If you need to convert RTF to text, here is a simple way of doing it:

    Public Shared Function ConvertRtfToText(ByVal input As String) As String
      Dim returnValue As String = String.Empty
      Using converter As New System.Windows.Forms.RichTextBox()
        converter.Rtf = input
        returnValue = converter.Text
      End Using
      Return returnValue
    End Function

Tip Submitted By: David McCarter

This code and more like it can be found in the dotNetTips.Utility assembly on the CodePlex site: http://www.codeplex.com/dotNetTipsUtility


 
Categories: VB.NET | WinForms

The code below shows you how to ignore all input unless it's a number:

private void searchText_KeyPress(object sender, KeyPressEventArgs e)
{
 if (e.KeyChar != 8)
 {
  if (char.IsNumber(e.KeyChar) == false)
  {
   e.Handled = true;
}
}

I allow the backspace keypress by checking for character 8. You can easily modify this code to suit your needs.

 

Tip Submitted By: David McCarter


 
Categories: WinForms

The Power Pack controls consist of:

  • BlendPanel. This provides a background for a form where the color fades from one shade to another.
  • UtilityToolbar. This is a toolbar whose look and feel is similar to the Internet Explorer toolbar.
  • ImageButton. This is a button that displays a graphic over a transparent background.
  • NotificationWindow. This displays text and graphics in a pop-up window (commonly known as "toast").
  • TaskPane. This is a container that provides collapsible frames for displaying additional information on a form.
  • FolderViewer. This displays directories in a hierarchical format.
  • FileViewer. This displays a list of the files in a specified directory.

For more information, go to: http://msdn.microsoft.com/vbasic/default.aspx?pull=/library/en-us/dv_vstechart/html/vbpowerpack.asp


 
Categories: dotNetDave | Link | VB.NET | WinForms

The User Interface Process Application Block provides a simple yet extensible framework for developing user interface processes. It is designed to abstract the control flow and state management out of the user interface layer into a user interface process layer. This helps you write generic code for the control flow and state management for different applications types (for example, Web and Windows) and helps manage user's tasks in complex scenarios (for example, suspending and resuming tasks).

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=98c6cc9d-88e1-4490-8bd6-78092a0f084e&DisplayLang=en


 
Categories: WinForms

November 6, 2003
@ 01:46 AM

It’s not as hard as you might think in .NET. In the code below, just send the text and the Font object that, for example, the TextBox is using.

public static int GetTextWidth(string dataText, Font dataFont)
{
  return Graphics.FromImage(new Bitmap(1,1)).MeasureString(dataText, dataFont).ToSize().Width;
}

Tip Submitted By: David McCarter


 
Categories: Csharp | WinForms

When I was putting data from a DataTable as shown in the code below:

DataView locationsView = new DataView(MyDataSet.Tables["locations"]);
locationsView.Sort = "name ASC";
lstLocations.ValueMember = "key";
lstLocations.DisplayMember = "name";
lstLocations.DataSource = locationsView;

I got a very strange result as seen below:

Once I set the Sorted property to False, it worked fine. Go figure.

Bug Submitted By: David McCarter


 
Categories: Bugs | Csharp | WinForms

Because when you databind the data to the control, all previous data gets wiped out, so you have to add the new item afterwards. Also, it will appear at the end of the list. I don't know of a way around that.

This code adds and selects an empty list item:

nameList.DataSource = MyDataTable
nameList.DataTextField = "Name"
nameList.DataValueField = "ID"
nameList.DataBind()
nameList.Items.Add("")
nameList.Items.FindByText("").Selected = True

Tip Submitted By: David McCarter


 
Categories: WinForms