Skip to main content

Windows form color

  'A form with custom border and title bar.

    'Some functions, such as resize the window via mouse, are not implemented yet. 



    'The color and the width of the border.

    Private borderColor As Color = Color.GreenYellow

    Private borderWidth As Integer = 3

    'The color and region of the header.

    Private headerColor As Color = Color.GreenYellow

    Private headerRect As Rectangle

    'The region of the client.

    Private clientRect As Rectangle

    'The region of the title text.

    Private titleRect As Rectangle

    'The region of the minimum button.

    Private miniBoxRect As Rectangle

    'The region of the maximum button.

    Private maxBoxRect As Rectangle

    'The region of the close button.

    Private closeBoxRect As Rectangle

    'The states of the three header buttons.

    Private miniState As ButtonState

    Private maxState As ButtonState

    Private closeState As ButtonState

    'Store the mouse down point to handle moving the form.

    Private x As Integer = 0

    Private y As Integer = 0

    'The height of the header.

    Const HEADER_HEIGHT As Integer = 25

    'The size of the header buttons.

    ReadOnly BUTTON_BOX_SIZE As Size = New Size(15, 15)


    Private Sub CustomBorderColorForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Hide the border and the title bar.

        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

    End Sub


    Private Sub CustomBorderColorForm_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        'Draw the header.

        Using b As Brush = New SolidBrush(borderColor)

            e.Graphics.FillRectangle(b, headerRect)

        End Using

        'Draw the title text

        Using b As Brush = New SolidBrush(Me.ForeColor)

            e.Graphics.DrawString(Me.Text, Me.Font, b, titleRect)

        End Using

        'Draw the header buttons.

        If Me.MinimizeBox Then

            ControlPaint.DrawCaptionButton(e.Graphics, miniBoxRect, CaptionButton.Minimize, miniState)

        End If

        If Me.MinimizeBox Then

            ControlPaint.DrawCaptionButton(e.Graphics, maxBoxRect, CaptionButton.Maximize, maxState)

        End If

        If Me.MinimizeBox Then

            ControlPaint.DrawCaptionButton(e.Graphics, closeBoxRect, CaptionButton.Close, closeState)

        End If

        'Draw the border.

        ControlPaint.DrawBorder(e.Graphics, clientRect, borderColor, _

            borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid)

    End Sub


    'Handle resize to adjust the region ot border, header and so on.

    Private Sub CustomBorderColorForm_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize

        headerRect = New Rectangle(Me.ClientRectangle.Location, New Size(Me.ClientRectangle.Width, HEADER_HEIGHT))

        clientRect = New Rectangle(New Point(Me.ClientRectangle.Location.X, Me.ClientRectangle.Y + HEADER_HEIGHT), _

            New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height - HEADER_HEIGHT))

        Dim yOffset = (headerRect.Height + borderWidth - BUTTON_BOX_SIZE.Height) / 2

        titleRect = New Rectangle(yOffset, yOffset, _

                                Me.ClientRectangle.Width - 3 * (BUTTON_BOX_SIZE.Width + 1) - yOffset, _

                                BUTTON_BOX_SIZE.Height)

        miniBoxRect = New Rectangle(Me.ClientRectangle.Width - 3 * (BUTTON_BOX_SIZE.Width + 1), _

                                    yOffset, BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)

        maxBoxRect = New Rectangle(Me.ClientRectangle.Width - 2 * (BUTTON_BOX_SIZE.Width + 1), _

                                    yOffset, BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)

        closeBoxRect = New Rectangle(Me.ClientRectangle.Width - 1 * (BUTTON_BOX_SIZE.Width + 1), _

                                    yOffset, BUTTON_BOX_SIZE.Width, BUTTON_BOX_SIZE.Height)

        Me.Invalidate()

    End Sub



    Private Sub CustomBorderColorForm_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

        'Start to move the form.

        If (titleRect.Contains(e.Location)) Then

            x = e.X

            y = e.Y

        End If


        'Check and press the header buttons.

        Dim mousePos As Point = Me.PointToClient(Control.MousePosition)

        If (miniBoxRect.Contains(mousePos)) Then

            miniState = ButtonState.Pushed

        ElseIf (maxBoxRect.Contains(mousePos)) Then

            maxState = ButtonState.Pushed

        ElseIf (closeBoxRect.Contains(mousePos)) Then

            closeState = ButtonState.Pushed

        End If


    End Sub


    Private Sub CustomBorderColorForm_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

        'Move and refresh.

        If (x <> 0 And y <> 0) Then

            Me.Location = New Point(Me.Left + e.X - x, Me.Top + e.Y - y)

            Me.Refresh()

        End If


    End Sub


    Private Sub CustomBorderColorForm_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

        'Reset the mouse point.

        x = 0

        y = 0


        'Check the button states and modify the window state.

        If miniState = ButtonState.Pushed Then

            Me.WindowState = FormWindowState.Minimized

            miniState = ButtonState.Normal

        ElseIf maxState = ButtonState.Pushed Then

            If Me.WindowState = FormWindowState.Normal Then

                Me.WindowState = FormWindowState.Maximized

                maxState = ButtonState.Checked

            Else

                Me.WindowState = FormWindowState.Normal

                maxState = ButtonState.Normal

            End If

        ElseIf closeState = ButtonState.Pushed Then

            Me.Close()

        End If


    End Sub


    'Handle this event to maxmize/normalize the form via double clicking the title bar.

    Private Sub CustomBorderColorForm_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDoubleClick

        If (titleRect.Contains(e.Location)) Then

            If Me.WindowState = FormWindowState.Normal Then

                Me.WindowState = FormWindowState.Maximized

                maxState = ButtonState.Checked

            Else

                Me.WindowState = FormWindowState.Normal

                maxState = ButtonState.Normal

            End If

        End If

    End Sub


Comments

Popular posts from this blog

Gemini software Dot net interview question for experienced

Gemini Interview questions 4-8 year experienced Dot net professional Gemini Interview questions 4-8 year experienced Dot net professional 1,Asp .net mvc request life cycle. 2,How routing works 3,Where codes for routing are written 4,What is attribute based routing in aap.net Mvc 5,Is multiple routes possible on a single action method. 6,What is action filters. 7,what is authentication and authorization filters 8,What are the types of authentication 8,What is the use of data annotation 9,Can we fire data annotation in client side. 10,What is model binding 11,what are Html helpers

TCS Interview Questions .Net experienced

   TCS Interview Questions .Net experienced 1)How did you implemented classes in your project? 2) Asp.net page life cycle? Explain briefly? 3) Asp.net page events? 4) How iis recognize that which web application we are requesting? 5) How iis recognize that web application is developed in which language? 6) How iis will use authentication? 7) Is it pages will compile in server? 8) In server pages will compile or execute? 9) What is diff between compile and execute? 10) What is appdomain? 11) What is aspnet_issapi.dll? 12) What is aspnet_wp.exe? 13) What is application? 14) What is view state? 15) Why we use view state? 16) What are the validation controls? Explain the use of validation controls? 17) Validation controls are client side or server side? 18) How to make raise JavaScript at the page is displaying? (which page event will use eg: page_load) ? 19) What is session? 20) Is it necessary to create session object? (ans :no)   21) What...

ASP .Net MVC

ASp .Net MVC 1. Explain MVC (Model-View-Controller) in general? MVC (Model-View-Controller) is an architectural software pattern that basically decouples various components of a web application. By using MVC pattern, we can develop applications that are more flexible to changes without affecting the other components of our application. §    “Model”, is basically domain data. §    “View”, is user interface to render domain data. §    “Controller”, translates user actions into appropriate operations performed on model. 2. What is ASP.NET MVC? ASP.NET MVC is a web development framework from Microsoft that is based on MVC (Model-View-Controller) architectural design pattern. Microsoft has streamlined the development of MVC based applications using ASP.NET MVC framework. 3. Difference between ASP.NET MVC and ASP.NET WebForms? ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front con...