C#
  Home arrow C# arrow Page 4 - C# Simplified, part 6: Working with Window...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

C# Simplified, part 6: Working with Windows Applications
By: Anand Narayanaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 20
    2005-06-07

    Table of Contents:
  • C# Simplified, part 6: Working with Windows Applications
  • My first WinForm application
  • Code Analysis
  • Working with WinForm controls using Visual Studio .NET

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C# Simplified, part 6: Working with Windows Applications - Working with WinForm controls using Visual Studio .NET


    (Page 4 of 4 )

    It is very easy to add controls using Visual Studio .NET. You don't have to write any code as explained in the above walkthroughs.

    Start a new Visual C# .NET project (File | New | Project -> Visual C# Projects -> Windows Application) and add a TextBox and a Button control using ToolBox. You should be able to see the Properties Window on the right side. Otherwise, press F4 to make it visible. You can modify the various properties of a WinForm control using this window as shown in Figure 6.3.

    Figure 6.3 Properties Window

    You can also select the required control from the top drop-down list and read a short description of each of the properties from the bottom section of this window. Double click anywhere on the Form to view the code generated by Visual Studio .NET.

    Working with TextBoxes

    With the help of Textboxes, you can enter information. That is why this control plays an important role in all applications. The entered information can be saved to a file, XML file or a database, according to your requirements. Textboxes are of two types, SingleLine and MultiLine. The difference between these two types is that multi-line boxes contain scroll bars and users can enter more that one line of text into them. It is similar to TextArea in HTML.

    The super class of this control is TextBoxBase. This class provides functionalities for advanced controls like RichTextBoxes. Listing 6.6 illustrates the working of a multi-line textbox control:

    Listing 6.6

    001: // MyText.cs

    002: // ---------

    003: using System;

    004: using System.Drawing;

    005: using System.Windows.Forms;

    006:

    007: public class MyText: Form

    008: {

    009: // Object of TextBox created

    010: TextBox t1 = new TextBox();

    011:

    012: MyText()

    013: {

    014: this.Controls.Add(t1);

    015: t1.Location = new Point(50,50);

    016: t1.Size = new Size(200,70);

    017: t1.Multiline = true;

    018: t1.ScrollBars = ScrollBars.Vertical;

    019: t1.TextAlign = HorizontalAlignment.Center;

    020: t1.CharacterCasing = CharacterCasing.Upper;

    021: this.Text = "TextBox Control Demo";

    022: }

    023:

    024: public static void Main()

    025: {

    026: Application.Run(new MyText());

    027: }

    028: }

    Compilation

    csc MyText.cs

    Execution

    MyText

    Output

    In the Textbox, whatever you enter will appear in uppercase, because of line 20. Also, the text will be aligned to center due to the statement in line 19. In Visual Studio .NET, you can change the above properties using the properties window after selecting the TextBox.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    C# ARTICLES

    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#
    - Working with Regular Expressions in C#
    - Sending Simple E-Mail in C#
    - Building C# Comparable Objects: IComparable ...
    - Color Transformation Applications in C# GDI+...
    - Performing Color Transformation Operations i...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT