approached VB.net (iii) source code detailed-the preliminary discussion of the use of color

Source: Internet
Author: User
Tags exit integer reference tostring
Detailed approach to vb.net (iii) source code detailed-the preliminary discussion of the use of color

Create a new project and add the following controls
1. Label control: label1,label2,labred, Labblue,labgreen
2. PictureBox Control: PictureBox1
3. Button control: Button1
Set the Form1 Opacity property to 80% to set the transparent form
Grab a color picture in office as a BMP format and set it to the PictureBox1 backgroundimage, which is the background picture
Option Strict off ' close Strict off
Imports System.ComponentModel ' Reference family name
Imports system.drawing ' Reference family name
Imports system.winforms ' Reference family name
' The following routines I'll write out all the family names and subclasses, so that you don't see it, and if you know what it means, you can use the method based on the ellipsis.

Public Class Form1
Inherits System.WinForms.Form ' references from System.WinForms.Form class to Form1
Public Pixx, Pixy as Integer ' declares two 32-bit variables and uses public to define his share among all members of the class
Public APR as Boolean = False ' declares two 32-bit variables, with public define him to share with all members of the class and initialize his value to False
Public Sub New () ' Create a new form
MyBase.New () ' Calls
Form1 = Me ' defines the current value of the Me keyword as Form1
' This is required by the Win Form Designer.
InitializeComponent () ' The code written below is equivalent to the code written in VB6 's form_ load
Call Me_load () ' You can write a subroutine that calls him here, of course you can simply write another process name like Me_beginform
' Todo:add any initialization on the InitializeComponent () call
End Sub

' Form overrides dispose to clean up the component list.
Public Overrides Sub Dispose () ' The code written under this is equivalent to the code written in VB6 's form_ unload
Mybase.dispose () ' Calls
Components. Dispose () ' Unload component
End Sub


The following paragraph #region "Windows Form Designer generated code" is not necessary to see,
All I wrote here is for you to be able to paste the run directly
#Region "Windows Form Designer generated code"

' Required by the Windows Form Designer
Private Components as System.ComponentModel.Container

Private WithEvents Label2 as System.WinForms.Label


Private WithEvents LAB4 as System.WinForms.Label
Private WithEvents Lab3 as System.WinForms.Label
Private WithEvents Lab2 as System.WinForms.Label
Private WithEvents Lbblue as System.WinForms.Label
Private WithEvents Lbgreen as System.WinForms.Label
Private WithEvents lbred as System.WinForms.Label

Private WithEvents Button1 as System.WinForms.Button
Private WithEvents Label1 as System.WinForms.Label
Private WithEvents PictureBox1 as System.WinForms.PictureBox

Dim WithEvents Form1 as System.WinForms.Form

' Note:the following procedure is required by the Windows Form Designer
' It can be modified using the ' Windows Form Designer.
' Do not modify it using the ' Code Editor.
Private Sub InitializeComponent ()
Dim resources as System.Resources.ResourceManager = New System.Resources.ResourceManager (GetType (FORM1))

Me.components = New System.ComponentModel.Container ()
Me.lbblue = New System.WinForms.Label ()
ME.LAB2 = New System.WinForms.Label ()
Me.label2 = New System.WinForms.Label ()
Me.label1 = New System.WinForms.Label ()
ME.LAB3 = New System.WinForms.Label ()
Me.lbgreen = New System.WinForms.Label ()
me.lbred = New System.WinForms.Label ()
ME.LAB4 = New System.WinForms.Label ()
Me.picturebox1 = New System.WinForms.PictureBox ()
Me.button1 = New System.WinForms.Button ()

' @design me.trayheight = 0
' @design Me.traylargeicon = False
' @design Me.trayautoarrange = True
Lbblue.location = New System.Drawing.Point (216, 200)
Lbblue.size = New System.Drawing.Size (112, 32)
Lbblue.borderstyle = System.WinForms.BorderStyle.Fixed3D
Lbblue.tabindex = 6
Lbblue.backcolor = System.Drawing.Color.Blue

Lab2.location = New System.Drawing.Point (8, 176)
Lab2.text = "R="
Lab2.size = New System.Drawing.Size (100, 23)
Lab2.forecolor = System.Drawing.SystemColors.ActiveCaptionText
Lab2.font = New System.Drawing.Font ("XXFarEastFont-Arial", 12!, System.Drawing.FontStyle.Bold)
Lab2.tabindex = 7

Label2.location = New System.Drawing.Point (248, 8)
Label2.size = New System.Drawing.Size (48, 96)
Label2.borderstyle = System.WinForms.BorderStyle.Fixed3D
Label2.tabindex = 10

Label1.location = New System.Drawing.Point (192, 80)
Label1.size = New System.Drawing.Size (48, 88)
Label1.borderstyle = System.WinForms.BorderStyle.Fixed3D
Label1.tabindex = 1

Lab3.location = New System.Drawing.Point (112, 176)
Lab3.text = "g="
Lab3.size = New System.Drawing.Size (104, 24)
Lab3.forecolor = System.Drawing.SystemColors.ActiveCaptionText
Lab3.font = New System.Drawing.Font ("XXFarEastFont-Arial", 12!, System.Drawing.FontStyle.Bold)
Lab3.tabindex = 8

Lbgreen.location = New System.Drawing.Point (112, 200)
Lbgreen.size = New System.Drawing.Size (104, 32)
Lbgreen.borderstyle = System.WinForms.BorderStyle.Fixed3D
Lbgreen.tabindex = 5
Lbgreen.backcolor = System.Drawing.Color.Lime

Lbred.location = New System.Drawing.Point (8, 200)
Lbred.size = New System.Drawing.Size (104, 32)
Lbred.borderstyle = System.WinForms.BorderStyle.Fixed3D
Lbred.tabindex = 4
Lbred.backcolor = System.Drawing.Color.Red

Lab4.location = New System.Drawing.Point (216, 176)
Lab4.text = "b="
Lab4.size = New System.Drawing.Size (112, 24)
Lab4.forecolor = System.Drawing.SystemColors.ActiveCaptionText
Lab4.font = New System.Drawing.Font ("XXFarEastFont-Arial", 12!, System.Drawing.FontStyle.Bold)
Lab4.tabindex = 9

Picturebox1.cursor = System.Drawing.Cursors.Hand
Picturebox1.backgroundimage = CType (resources. GetObject ("Picturebox1.backgroundimage"), System.Drawing.Image)
Picturebox1.location = New System.Drawing.Point (8, 8)
Picturebox1.size = New System.Drawing.Size (176, 168)
Picturebox1.tabindex = 0
Picturebox1.tabstop = False

Button1.location = New System.Drawing.Point (304, 48)
Button1.forecolor = System.Drawing.SystemColors.ControlLightLight
Button1.size = New System.Drawing.Size (24, 120)
Button1.tabindex = 2
Button1.Text = "Exit"
Me.Text = "Form1"
Me.autoscalebasesize = New System.Drawing.Size (6, 14)
Me.borderstyle = System.WinForms.FormBorderStyle.None
Me.backcolor = System.Drawing.Color.Black
Me.clientsize = New System.Drawing.Size (344, 256)
Me.opacity = 0.8#

ME.CONTROLS.ADD (LABEL2)
ME.CONTROLS.ADD (LAB4)
ME.CONTROLS.ADD (LAB3)
ME.CONTROLS.ADD (LAB2)
ME.CONTROLS.ADD (Lbblue)
ME.CONTROLS.ADD (Lbgreen)
ME.CONTROLS.ADD (lbred)
ME.CONTROLS.ADD (Button1)
ME.CONTROLS.ADD (LABEL1)
ME.CONTROLS.ADD (PictureBox1)
End Sub

#End Region
The above section #region "Windows Form Designer generated code" is not necessary to see,
All I wrote here is for you to be able to paste the run directly

Sub Me_load ()
System. WinForms.MessageBox.show ("Welcome to my first vb.net program", "Mini Color Picker", MessageBox.) OK Bitor MessageBox. Iconasterisk)
End Sub

Protected Sub button1_click (ByVal sender As Object, ByVal e as System.EventArgs) ' sender is the object that sends the data, E is the object of the collection parameter
End ' Exit program
End Sub

Protected Sub PictureBox1_Click (ByVal sender As Object, ByVal e as System.EventArgs) ' sender is the object that sends the data, E is the object of the collection parameter
If Apr = True Then System. WinForms.MessageBox.show ("Please move the mouse back again to take color", "Miniature Color Picker", MessageBox.) OK Bitor MessageBox. Iconasterisk)
Apr = True ' After the color is selected, the analysis of RGB stops
Label2. BackColor = Label1. BackColor ' The source color to the destination color
End Sub

Public Function GetPixel () as System.Drawing.Color ' This is also an alias of a function
Dim PM as System.Drawing.Bitmap ' declares an object
PM = Picturebox1.backgroundimage ' Set an instance (note the previous option Strict off cannot be less)
return PM. GetPixel (Pixx, Pixy) ' Returns a value to the function using return, which is the GetPixel function that invokes the System.Drawing.Bitmap class
' If it is a member procedure, not a function, use the method call of the calling procedure, such as the SetPixel procedure for the System.Drawing.Bitmap class:
' Public Sub setpixel (ByVal X As Integer, ByVal Y As Integer, ByVal pcolor as System.Drawing.Color)
' Dim PM as System.Drawing.Bitmap
' PM = Picturebox1.backgroundimage
' PM. SetPixel (X, y, Pcolor)
' End Sub ' Of course this code can't be placed inside a function!!!
End Function


Public Sub Picturebox1_mousemove (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles picturebox1.m Ousemove
Dim Pcolor as System.Drawing.Color ' declares a variable of a Color type
Dim Strpc As String ' declares a variable of type string
Dim Cltmpa, Cltmpr, Cltmpg, CLTMPB As String ' Declare three string types of variables

If Apr Then Exit Sub ' Give a little time to set a pixel

Pcolor = GetPixel ' calls the GetPixel, you can also use a common variable in this example by using the arguments in parentheses to pass the value of X,y Pixx,pixy
LABEL1. BackColor = Pcolor ' Sets the background color of the LABEL1 control
Strpc = Pcolor.tostring ' ToString is the data that turns pcolor from System.Drawing.Color to string
Pixx = E.x ' E is a parameter and is treated as an object, E.x is a member of the object, indicating the current coordinate X value of the mouse
Pixy = E.y:label1. BackColor = GetPixel ' keyboard is not good, can not enter, had to play ":" instead of branch

Cltmpa = strpc.substring (strpc. IndexOf ("A"), (Strpc. INDEXOF ("R")-2)-Strpc. IndexOf ("A")) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
Cltmpa = Cltmpa. Substring (Cltmpa. IndexOf ("=") + 1, Cltmpa. Length-(Cltmpa. IndexOf ("=") + 1)) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
' Get red
CLTMPR = strpc.substring (strpc. IndexOf ("R"), (Strpc. INDEXOF ("G")-2)-Strpc. IndexOf ("R")) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
CLTMPR = Cltmpr. Substring (CLTMPR. IndexOf ("=") + 1, cltmpr. Length-(CLTMPR. IndexOf ("=") + 1)) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
' Get Green
Cltmpg = strpc.substring (strpc. IndexOf ("G"), (Strpc. INDEXOF ("B")-2)-Strpc. IndexOf ("G")) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
Cltmpg = Cltmpg. Substring (Cltmpg. IndexOf ("=") + 1, Cltmpg. Length-(Cltmpg. IndexOf ("=") + 1)) ' substring a string for us, like the mid function of VB6, instead of the Left,right function
' Get Blue
CLTMPB = strpc.substring (strpc. IndexOf ("B"), Strpc. Length-strpc. IndexOf ("B")-1) ' substring for us sub A string, as if the VB6 of the mid function, replace the Left,right function
CLTMPB = CLTMPB. Substring (CLTMPB. IndexOf ("=") + 1, CLTMPB. Length-(CLTMPB. IndexOf ("=") + 1)) ' substring a string for us, like the mid function of VB6, instead of the Left,right function

Lbred. BackColor = System.Drawing.Color.FromARGB (Cltmpa. ToInt32, Cltmpr.toint32, 0, 0) ' FromArgb is the RGB of VB6, just one more alpha (Alpha) parameter in the first place.
Lbgreen. BackColor = System.Drawing.Color.FromARGB (Cltmpa. ToInt32, 0, cltmpg.toint32, 0) ' Extract Green
Lbblue. BackColor = System.Drawing.Color.FromARGB (Cltmpa. ToInt32, 0, 0, cltmpb.toint32) ' Extract Blue

LAB2. Text = "r=" & Cltmpa ' shows R value
LAB3. Text = "g=" & Cltmpg ' shows G value
LAB4. Text = "b=" & CLTMPB ' shows B value
End Sub
' Cool, drag is no border
Private Sub Form1_mousedown (ByVal eventsender as Object, ByVal e as System.WinForms.MouseEventArgs)
' The Drop-down list in the form in the MouseDown event is not found, write one yourself, plus (ByVal eventsender as Object, ByVal e as System.WinForms.MouseEventArgs)
' me.capture () = False ' releases mouse capture, equivalent to API ReleaseCapture ()
' Me.sendmessage (&ha1s, 2, 0) ' Well, this is which SendMessage API, but the first handle parameter is no longer used.
End Sub

Public Sub Picturebox1_mouseleave (ByVal sender as Object, ByVal e as System.EventArgs) Handles Picturebox1.mouseleave
Apr = False ' This is very useful, is the mouse to leave a control when the event, so that a dynamic 3D button is very convenient
End Sub

End Class
This article is object-oriented (for VB). NET, I don't guarantee that there is a twist on the traditional object-oriented theory (I've never been object-oriented, and I'm not very fond of object-oriented, at least not the same way to face the second windows),
But this article does make beginners (I believe a lot of people confused) quickly using vb.net to develop simple programs,
My text is to inspire more people to "not necessarily much of him" (VB. Net) ".
If
If you are an expert in a (SP), B (ASIC), C (XX), D (Elphi), E (XP), F (OX), G (O)
and is not in the same hands with me
Then This article really did not see the need (as China's reserve programmer, please forgive me for this common problem and complain a lot)
Else
Still, sincerely look forward to your generous enlighten VB. NET Chinese website: http://vbnetcn.126.com
End If
Vb. NET Chinese station today basically do a good job of the example source program, please download the relevant website 200k (April 16)


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.