A c # IP address control

Source: Internet
Author: User
ArticleDirectory
    • Public instance Properties
    • Public instance methods
    • Download Demo project-34.2 KB
    • Download source-20.5 KB
    • Download Demo project [vs05]-36 KB
    • Download source [vs05]-20 KB
    • Download Demo project [vs08]-36.2 KB
    • Download source [vs08]-20.2 KB

Introduction

Why didn't Microsoft include an IP address control in the stock toolbox for Visual Studio. NET? I needed something similar to the MFCCipaddressctrlClass in a C # application recently, and was forced to roll my own. I tried to mimic the behaviorCipaddressctrlUsing C # Here, and hopefully I 've succeeded.

Background

IpaddresscontrolIs really a compositeUsercontrolThat aggregates four specializedTextboxControls of TypeFieldctrlAnd three specializedControlS of TypeDotctrl. Here's a picture:

TheFieldctrlS do some validation and keyboard filtering, in addition to standardTextboxBehavior.DotctrlS do nothing but draw a dot.

Using the code

Once the library containingIpaddresscontrol(Ipaddresscontrollib. dll) Is built, add the control to the toolbox in Visual Studio. From the toolbox, just drag the control onto a form and you're ready to go. The interfaceIpaddresscontrolIs very simple.

Public instance Properties
    • Autoheight:GetS orSetS a value indicating whether the control is automatically sized vertically according to the current font and border. The default value isTrue.
    • Blank:GetS a value indicating whether all of the fields in the control are empty.
    • Borderstyle:GetS orSetS the border style of the control. The default value isBorderstyle. fixed3d.
    • Readonly:GetS orSetS a value indicating if the control is read-only.
Public instance methods
    • clear : clears the contents of the Control.
    • getaddressbytes : returns an array of byte S representing the contents of the fields, index 0 being the leftmost field.
    • setaddressbytes : set S the values of the fields using an array of byte S, index 0 being the leftmost field.
    • setfieldfocus : set S the keyboard focus to the specified field in the control.
    • setfieldrange : set S the lower and higher range of a specified field in the control.

The above properties and methods are in addition to the stock properties and methodsUsercontrol. Stock properties suchText,Enabled, AndFont-- As well as stock methods suchTostring ()-- Work as expected. The client code can register a handler for the public event,Fieldchangedevent, To be notified when any text in the fields of the control changes.

Note thatTextAndTostring ()May not return the same value. If there are any empty fields in the control,TextWill return a value that will reflect the empty fields.Tostring ()Will fill in any empty fields with that field'sRangelowerValue. Also, if you are using the control to createIPaddress, You can easily do so using this control'sGetaddressbytes ()Method:

Collapse Copy code
 
IPaddress =NewIPaddress (ipaddresscontrol. getaddressbytes ());
History
  • 27 Apr 2008

    • Added propagationKeydown,Keyup, AndPreviewkeydownEvents.Keys. EnterAndKeys. ReturnWill now propagateKeypressEvent.
  • 23 Oct 2007
    • ReadonlyShocould now really be read-only. Thanks to t_suzuki for reporting this bug.
  • 27 Sep 2007
    • Added proper event propagation for focus, keypress, and some mouse events.
    • AddedAllowinternaltabAndAnyblankProperties.
    • Removed superfluous code.
    • Removed a potential resource leak when calculating text size and addedNullCheckSetaddressbytes ().
    • Compliant with fxcop 1.35.
  • 13 Jun 2007
    • Text Set in design mode is persisted.
    • Removed overrideAutosize. UseAutoheightInstead.
    • [Vs05] modified size calculations to conserve horizontal space.
  • 6 Mar 2007
    • Now checksNullWhen parsing incoming text.
  • 21 Feb 2007
    • Added handling of [backspace] into SS fields. Thanks to Antony for reporting this bug.
    • Added better handling of [delete], and new handlers for [home] and [end].
    • [Vs05] modifiedMinimumsizePropertyDotcontrolTo tighten up the spacing.
  • 5 May 2006
    • [Vs05] addedBaselineToSnaplinesCollection forControldesignerClass. MadeTextProperty browsable in design mode. Fixed the control sizing bug when large fonts are used.
  • 13 Oct 2005
    • Compliant with fxcop 1.32.
  • 17 Sep 2005
    • Enhanced to support Windows XP visual styles. Thanks to Carlos for requesting this.
  • 3 Aug 2005
    • Bug fixFocusedProperty. Thanks to Mario for reporting this.
  • 22 Mar 2005
    • Added a callOntextchanged ()For the control when the text of any field changes. Thanks to Bertrand for pointing that out.
  • 6. Feb 2005
    • Added missing key handlers. Thanks to norm and ed for the heads-up on missing key handlers.
    • Added sizing.
    • AddedReadonlyProperty.
    • Non-standard color choices now render properly.
    • Added an event to your y clients of text change.
  • 20 Jan 2005-initial release.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.