Come near VB.net (11) Arbitrary form appearance (skin wonderful source)

Source: Internet
Author: User
Tags exit chr integer network function reference tostring
Come near VB.net (11) Arbitrary form appearance (skin wonderful source)
A few days ago due to cope with manuscripts, the promise of the source code postponed a few days, today to stay up to write him out, please forgive me. In addition, I would like to say some digression, before I have said in the article, said vb.net object-oriented plagiarism Java,delphi no actual basis (you can not always see the object as the Linux core of the same source technology, he is mainly a guiding ideology), this sentence itself has a logical error, Can you tell me who copied Java and Delphi? The answer can only be Smalltalk object-oriented earlier (see Wangguorong's article). VC object-oriented everyone shut up, but I personally think that in Windows programming (excluding network applications) VC is still the most powerful language, and VC programmers almost no one came out to say these boring words. So who's talking?

This argument originated in foreign articles (referring to Internet applications suspected of imitating Java, if it is written in a Windows program is unfounded), and the author in later writing very clearly told everyone to correct this statement. I have mentioned it repeatedly. But some people turn a blind eye. We now say vb.net how too early a bit, we are in practice groping, use will not use, there is no basis for speculation some unwise. A lot of learning Java tells you to learn Java before learning vb.net. This is a bit weird, at least for now, not seeing Java programmers write the vb.net program we can learn. Because the thought of the object of the image does not mean that it has everything.

Now object-oriented really some deified, this incredible, programmers are not philosophers, is to work all night to learn to create, as if not romantic! And now it is a part of the people romantic.

No matter how Microsoft praises his network function, I believe in the near future, VB. NET will become the fastest, most important, and most suitable application programming language for the Windows platform (I don't involve web apps). Of course, no one is the most powerful, the world seems to be the most powerful! And I'm not interested in his web apps. Everyone has their own way. As we all say how VB is suitable for the development of the database. But do you believe that a person never touches the database can write a very promising program, each person has the right to choose their own way! If you have no interest in web apps, will Java be a good choice?

I personally think that whether it is java,delphi, or vb.net or even C + +, each has its own strengths. Each has its own purpose. No good or bad points, programming is the most important inspiration, is a broad vision, is a broad bosom. Anyone who wants to belittle others is exposing his own humble opinion and ignorance. Although I am learning VB, but I entered the forum after the Delphi, I also moved, here also has a lot of conscientious, selfless dedication worthy of respect and learning. Tools can never conquer human nature! The foreigner is not because this paper is made by the Chinese and not, nor because the gunpowder was invented by the Chinese and ashamed, nor because the origin of the binary system in China and grumble, science is across national boundaries, should not be overshadowed by political overtones.

I have been in a special introduction to Bill Gates's website to look at his life, want to see a lot of people. What can we say when we see the struggle of his life?

The above is a personal humble opinion (in view of my ignorance of the Delphi,java, the vb.net and the opposite like object technology part of misunderstanding), just talk about feelings, do not exaggerated, a masterpiece article. I write this to prevent some of the wrong mistakes in misleading beginners. In addition, I have repeatedly encouraged you to study and make some practical observations. Because of my own limitations and no mutual discussion, so each article to write out the effort is no less than write a project. Therefore, please reprint the article in contact with me after the text explicitly by the end of this article in the style annotated my website name, URL. Thank you for the first place!

In addition, in view of the requirements of some beginners, as well as the guidance of predecessors, I am in the source of the entry level of knowledge to annotate, if you think these are superfluous to you, please understand there are many people do not understand.


' Source code from vb.net Chinese station http://vbnetcn.126.com Hejianzhong Please respect the work of the author do not modify this information (AI ... ...). )

' ______________________________________________________________________________________________________________ _____

' -------------------------------------------------------------------------------------------------------------- -----

' Please first clear add lable (lbexit,lbpre,lbshow) control

' Set the BACKCOLR (background color) of the three lable controls in the property bar to system.desktop the desktop color under the System tab in the selection dialog box that appears

' Next, add the Axagent control this please refer to flops "come near VB.net (nine) Axagent animation form Implementation"

' Set the form background picture to sk1.gif please set in the BackgroundImage property bar

' All required pictures are made with Photoshop, if you don't do it to ' VB. NET Chinese forum to find me to help you do.

' Set the Text property of the Lbexit, which is displayed on the label, as exit

' Set the Text property of the Lbpre, which is displayed on the label, as form

' Set the Text property of the Lbshow, which is displayed on the label, as animation

' Sets the TextAlign of all labels (the way text is arranged) to center (centered)



Option Strict off option Strict

Imports System.ComponentModel ' Reference family name

Imports system.drawing ' Reference family name

Imports system.winforms ' Reference family name



Public Class Form1

Inherits System.WinForms.Form ' Inherits a form's class

Dim Genie as Agentobjects.iagentctlcharacterex ' declares an object of an agent

Const DataPath as String = "MERLIN." ACS "' Loads animation data

Public Frmpre as Form1 ' declares a new form, please do not use the initialization method here or use the new method

Public Imindex as Short ' declares an integer

Public Overloads Sub New () ' Each class typically has a new procedure that is called when you create a new object (using the new method)

MyBase.New () ' Call the New procedure of the parent class directly

Form1 = Me ' Set me ' keyword

InitializeComponent () ' Below is the initialization component, you can also use the call method below to page a child process (see previous article)

AxAgent1.Characters.Load ("MERLIN", DataPath) ' loads animation data

Genie = Axagent1.characters ("MERLIN") ' assigns the agent object to the declared object, simplifying the process of writing

Genie.languageid = &h409s ' Set speech ID

Call Skinregion (form1) ' Change skin for form (appearance)

End Sub

Overloads Sub New (ByVal strimage as String)

MyBase.New () ' Call the New procedure of the parent class directly

Form1 = Me ' Set me ' keyword

InitializeComponent () ' Below is the initialization component, you can also use the call method below to page a child process (see previous article)

lbexit.visible = False:lbShow.Visible = False:lbpre. Visible = False:label3. Visible = False ' New form does not display control

Me.top = me.top + 150 ' The position of the new form, top is the height from the tops of the screen

Call Skinregion (Form1, strimage) ' Change skin for form (appearance)

End Sub

' Using overloads to define two different new processes, using overloads in the new process can indirectly make a class very reusable, and if you don't understand why not write a new process, be sure to use the overload

' Then you have to look at the usage here and it will be instructive.

Public Overrides Sub Dispose () frees resources, terminating programs

Mybase.dispose () ' methods to invoke the parent class

Region1.dispose () ' Releasing GDI resources

Genie = Nothing ' frees up resources for animations

Components. Dispose () ' Release the resources that the component occupies

End Sub

' The following is a non-edit module, you don't have to look

#Region "Windows Form Designer generated code"



' Required by the Windows Form Designer

Private Components as System.ComponentModel.Container

Private WithEvents Lbshow as System.WinForms.Label

Private WithEvents Label3 as System.WinForms.Label

Private WithEvents LinkLabel3 as System.WinForms.LinkLabel

Private WithEvents Lbexit as System.WinForms.Label

Private WithEvents Lbpre as System.WinForms.Label

Private WithEvents AxAgent1 as Axagentobjects.axagent

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.lbpre = New System.WinForms.Label ()

Me.lbshow = New System.WinForms.Label ()

Me.label3 = New System.WinForms.Label ()

Me.axagent1 = New axagentobjects.axagent ()

Me.linklabel3 = New System.WinForms.LinkLabel ()

Me.lbexit = New System.WinForms.Label ()



Axagent1.begininit ()



' @design Me.trayheight = 90

' @design Me.traylargeicon = False

' @design Me.trayautoarrange = True

Lbpre. Location = New System.Drawing.Point (32, 72)

Lbpre. Text = "Form"

Lbpre. Size = New System.Drawing.Size (64, 24)

Lbpre. TabIndex = 10

Lbpre. BackColor = System.Drawing.SystemColors.Desktop

Lbpre. TextAlign = System.WinForms.HorizontalAlignment.Center



Lbshow.location = New System.Drawing.Point (32, 24)

Lbshow.text = "Animation"

Lbshow.size = New System.Drawing.Size (64, 24)

Lbshow.tabindex = 17

Lbshow.backcolor = System.Drawing.SystemColors.Desktop

Lbshow.textalign = System.WinForms.HorizontalAlignment.Center



Label3.location = New System.Drawing.Point (176, 16)

Label3.text = ""

Label3.size = New System.Drawing.Size (176, 88)

Label3.borderstyle = System.WinForms.BorderStyle.Fixed3D

Label3.tabindex = 16



Axagent1.size = New System.Drawing.Size (56, 40)

Axagent1.ocxstate = CType (resources. GetObject ("Axagent1.ocxstate"), System.WinForms.AxHost.State)

Axagent1.tabindex = 1

Axagent1.location = New System.Drawing.Point (232, 216)



Linklabel3.text = "LinkLabel3"

Linklabel3.size = New System.Drawing.Size (0, 16)

Linklabel3.tabindex = 15

Linklabel3.tabstop = True

Linklabel3.location = New System.Drawing.Point (352, 88)



Lbexit.location = New System.Drawing.Point (32, 48)

Lbexit.text = "Exit"

Lbexit.size = New System.Drawing.Size (64, 24)

Lbexit.tabindex = 11

Lbexit.backcolor = System.Drawing.SystemColors.Desktop

Lbexit.textalign = System.WinForms.HorizontalAlignment.Center



Me.Text = "Form1"

Me.autoscalebasesize = New System.Drawing.Size (6, 14)

Me.borderstyle = System.WinForms.FormBorderStyle.None

Me.backgroundimage = CType (resources. GetObject ("$this. BackgroundImage "), System.Drawing.Image)

Me.clientsize = New System.Drawing.Size (392, 288)



ME.CONTROLS.ADD (Lbshow)

ME.CONTROLS.ADD (LABEL3)

ME.CONTROLS.ADD (LINKLABEL3)

ME.CONTROLS.ADD (Lbexit)

ME.CONTROLS.ADD (Lbpre)

ME.CONTROLS.ADD (AXAGENT1)



Axagent1.endinit ()

End Sub



#End Region

' The above is a non edit module, you don't have to look

Protected Sub Lbexit_click (ByVal sender as Object, ByVal e as System.EventArgs)

If Frmpre <> nothing Then ' If a new form is loaded

Frmpre. Dispose () ' Terminate new form

Frmpre = Nothing ' frees up the resources occupied

End If

Me.dispose () ' Terminate program

End ' terminate the program completely (use this keyword if the program cannot exit)

End Sub





' The following is the animation process, in front of the article is very detailed, you can not see!

Protected Sub Lbshow_click (ByVal sender as Object, ByVal e as System.EventArgs)

Genie. left = 500 ' Set the position of the agent

Genie.show () ' Use Show method to display agent

Genie. MoveTo (180) ' MoveTo method is to move the agent to a location, and if you add a timer, you can easily let him run around on the screen ()

MessageBox. Show ("If you are mm, please press Ctrl+alt+del to close" & Chr & Chr () & "Do you really want to continue, until I don't move!" ")

Genie.speak ("Ni hao") ' makes a sound

MessageBox. Show ("Hello") dialog box, more parameters please see the previous related articles

Genie.speak ("WO SHI HAO KAN DI") ' makes a sound

MessageBox. Show ("I am good-looking") dialog box, more parameters please see previous related articles

Genie.speak ("NI SHI NAN KAN DI") ' makes a sound

MessageBox. Show ("You Are Ugly") dialog box, more parameters please see previous related articles

Genie.speak ("ZIA JIE MIMI") ' makes a sound

MessageBox. Show ("Goodbye MM") dialog box, more parameters please see previous related articles

Genie. Play ("wave") ' wave to greet

' mm Please do not be angry

' It's a little joke, if you want to really read Chinese, use the following

' Genie.speak ("cnstring", Cnstring.wav) ' Here's cnstring is the Chinese voice file

Genie. Hide () ' Hides the agent using the Hide method

End Sub



Protected Sub Lbpre_click (ByVal sender as Object, ByVal e as System.EventArgs)

If frmpre <> Nothing Then frmpre. Dispose () ' If the new form already exists, clear the

Dim Strim as String ' defines a character type variable

If Imindex <> 6 Then ' turn to think, that is, if we start from scratch by 6, I only have so many pictures.

Imindex = Imindex + 1

Else

Imindex = 1 ' Start from scratch

End If

Strim = "SK" & Imindex. ToString ' tostring means converting from a character type to a numeric type

' The label control in vb.net has the same function as the image control, not only to display text but also to display pictures, while in VB6 you can only display pictures of

Label3.image = Label3. Image.FromFile (System.WinForms.Application.StartUpPath & "& Strim &"). GIF ") ' Formfile is loading pictures from a path

' System.WinForms.Application.StartUpPath means the current directory, with the App.Path in the VB6

' Please note that the current directory used during debugging is in the bin directory and may be changed in the next version

Frmpre = New Form1 (Strim) ' Initializes an instance (object)

Frmpre. Visible = True ' Displays the new form, if not, you can't see anything!

End Sub







' Here is the code for the mobile form, please refer to the previous article

Private Sub Form1_mousedown (ByVal Eventsender as System.Object, ByVal EventArgs as System.WinForms.MouseEventArgs)

Me.capture = False ' release mouse capture

Me.sendmessage (&ha1s, 2, 0) ' This is the most famous API message function in VB6

End Sub

' Below is the event that occurs when the mouse moves _mousemove

Public Sub Lbpre_mousemove (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbpre. MouseMove

Lbpre. BackColor = System.drawing.Color.Black ' Set color

Lbpre. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbexit_mousemove (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbexit.mousemove

Lbexit.backcolor = System.drawing.Color.Black ' Set color

Lbexit.forecolor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbshow_mousemove (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles lbshow. MouseMove

Lbshow. BackColor = System.drawing.Color.BLack ' Set color

Lbshow. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub

' Below is the event that occurs when the mouse presses the _mousemove

Public Sub Lbpre_mousedown (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbpre. MouseDown

Lbpre. BackColor = System.drawing.Color.Blue ' Set color

Lbpre. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbexit_mousedown (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbexit.mousedown

Lbexit.backcolor = System.drawing.Color.Blue ' Set color

Lbexit.forecolor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbshow_mousedown (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbshow.mousedown

Lbshow. BackColor = System.drawing.Color.Blue ' Set color

Lbshow. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub



Public Sub Lbpre_mouseup (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbpre. MouseUp

Lbpre. BackColor = System.drawing.Color.Black ' Set color

Lbpre. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbexit_mouseup (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbexit.mouseup

Lbexit.backcolor = System.drawing.Color.Black ' Set color

Lbexit.forecolor = System. Drawing.Color.AliceBlue ' Set color

End Sub

Public Sub Lbshow_mouseup (ByVal sender as Object, ByVal e as System.WinForms.MouseEventArgs) Handles Lbshow.mouseup

Lbshow. BackColor = System.drawing.Color.BLack ' Set color

Lbshow. ForeColor = System. Drawing.Color.AliceBlue ' Set color

End Sub

' Here's what happened when the mouse left _mouseleave.

Public Sub Lbshow_mouseleave (ByVal sender as Object, ByVal e as System.EventArgs) Handles Lbshow.mouseleave

Lbshow. BackColor = System.drawing.Color.BlanchedAlmond ' Set color

Lbshow. ForeColor = System. Drawing.Color.Black ' Set color

End Sub

Public Sub Lbexit_mouseleave (ByVal sender as Object, ByVal e as System.EventArgs) Handles Lbexit.mouseleave

Lbexit.backcolor = System.drawing.Color.BlanchedAlmond ' Set color

Lbexit.forecolor = System. Drawing.Color.Black ' Set color

End Sub

Public Sub Lbpre_mouseleave (ByVal sender as Object, ByVal e as System.EventArgs) Handles Lbpre. MouseLeave

Lbpre. BackColor = System.drawing.Color.BlanchedAlmond ' Set color

Lbpre. ForeColor = System. Drawing.Color.Black ' Set color

End Sub

End Class



'############################################################################################################## #####

'!!! 0001!!! !!! NUM!!!!!!

' It is recommended that you do not modify this module to avoid unnecessary errors (this code is quite perfect) please back up the _______VB first if you want to modify it. NET Chinese station Hejianzhong

' This module can really be pasted into your program for use.

' Do not delete this information, I am free to provide you with this code, want to return is the minimum of respect, although the end user can not see, I still feel gratified

'!!! 0001!!! !!! NUM!!!!!!

Public Module SKin

Public Rect1 as New Rectangle (0, 0, 0, 0)

Public Region1 as New System.Drawing.Region (RECT1)

Public Sub skinregion (ByVal skform as Form, Optional ByVal skinnaskform as String = Nothing)

Dim X, Y, Transpix, Opacipix, Bgwidth, bgheight as Integer

Dim Rect2 as New Rectangle ()

Dim Firargb as Integer = GetPixel (Skform, 1, 1)

Dim Region1 as New System.Drawing.Region (RECT1)

Rect1 = Nothing

' skform.visible = False

If skinnaskform <> Nothing Then skform.backgroundimage = SKform.BackgroundImage.FromFile ( System.WinForms.Application.StartUpPath & "\" & Skinnaskform & ". gif")

Bgwidth = SKform.BackgroundImage.Width

Bgheight = SKform.BackgroundImage.Height

Skform.height = Bgheight

Skform.width = Bgwidth

For Y = 1 to BgHeight-1 ' Here reference the scanning method in VB6, please refer to the relevant information

X = 0

Todo

x = x + 1

while (GetPixel (Skform, x, Y) = Firargb) and (x < bgwidth)

x = x + 1

End While

Transpix = X

while (GetPixel (Skform, X, Y) <> Firargb) and (x < bgwidth)

x = x + 1

End While

Opacipix = X-1

If Transpix <= Opacipix Then

Rect2 = Rect2. FROMLTRB (TransPix-1, Y-1, Opacipix, Y)

Region1.union (RECT2)

Rect2 = Nothing

End If

Loop Until X >= bgwidth

Next Y

Skform.region = Region1

Skform.refresh ()

' skform.visible = True

End Sub

Public Function getpixel (ByVal skform as Form, ByVal x As Integer, ByVal y As Integer) As Integer

Dim pm as Bitmap = Skform.backgroundimage

Try

return PM. GetPixel (x, y). ToArgb

Catch

Exit Function

End Try

End Function

End Module



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.