473,846 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving Transparent Control

I wish to code a control that writes a text over a picturebox and that can
be dragged with mouse.

Here is what i've actually coded to obtain a similar effect, but as you can
see i've serious problems with trasparence

Create new project and add a button in the form and then insert a background
image to the form itself.

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim NewTextLayer As New LayerText
With NewTextLayer
.Text = "Click Here!"
.ForeColor = Color.Blue
.Font = New Font("Arial Black", 20)
.Angle = 10

.Size = New System.Drawing. Size(200, 100)
.Location = New System.Drawing. Point(100, 30)
End With
Me.Controls.Add (NewTextLayer)
End Sub
This is a class:
Imports System.Drawing
Imports System.Drawing. Drawing2D

Public Class LayerText : Inherits Control
Private _backBuffer As Bitmap
Private _angle As Single
Private dragPoint As Point

Public Property Angle() As Single
Return _angle
End Get
Set(ByVal Value As Single)
If _angle <> Value Then
_angle = Value
End If
End Set
End Property
Public Sub New()
SetStyle(Contro lStyles.DoubleB uffer Or _
ControlStyles.A llPaintingInWmP aint Or
ControlStyles.U serPaint Or _
ControlStyles.O paque, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If BackgroundImage Is Nothing Then
If Not (Parent.Backgro undImage Is Nothing) Then
e.Graphics.Draw Image(Parent.Ba ckgroundImage, _
New Rectangle(0, 0, Width, Height), _
Me.Left, Me.Top, Width, Height, GraphicsUnit.Pi xel)
e.Graphics.Fill Rectangle(New SolidBrush(Pare nt.BackColor), _

New Rectangle(0, 0, Width, Height))
End If
End If

If _backBuffer Is Nothing Then
_backBuffer = New
Bitmap(Me.Clien tSize.Width,Me. ClientSize.Heig ht)
End If

Dim nGraphics As Graphics = Nothing
nGraphics = Graphics.FromIm age(_backBuffer )

With nGraphics
'.Clear(Color.T ransparent)

.RotateTransfor m(Angle)
.SmoothingMode = SmoothingMode.H ighQuality

.DrawString(Tex t, Font, New SolidBrush(Fore Color), New
End With

e.Graphics.Draw ImageUnscaled(_ backBuffer, 0, 0)
End Sub

Private Sub TextLayer_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) andles MyBase.MouseDow n
If e.Button = MouseButtons.Le ft Then
dragPoint.X = e.X
dragPoint.Y = e.Y
End If
End Sub
Private Sub TextLayer_Mouse Move(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseMov e
If e.Button = MouseButtons.Le ft Then
Location = New Point(Left + e.X - dragPoint.X, Top + e.Y -
End If
End Sub

End Class
Please any tips to enhance this code is welcomed
Thacks in andvance

Nov 20 '05 #1
0 1255

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Efkas | last post by:
My application have some level : 1. MyButton class with Label inheritance 2. MyComponent as User Control loading and positionning some of MyButtons 3. MyApp loading and positionning MyComponent I prefer don't insert a background in MyComponent, and using the MyApp one as general background with MyComponent positionned, but I am not able to have MyComponent background transparent.
by: Steve Koon | last post by:
Any thoughts on getting this project to work or suggesting another method would be appreciated. Steve ========================================== Project: A Windows Form which acts as a Whiteboard. The Form contains 3
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making some controls that aren't rectangular and it won't be pretty if I end up with a grey rectangle behind each one. http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskGivingYourControlTransparentBackground.asp?frame=true
by: jcrouse | last post by:
I use the following three subs to click on a label and reposition it at runtime: Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblP1JoyUp.MouseDown myMouseDown = True mouseX = Cursor.Position.X - Me.Location.X - (lblP1JoyUp.Width / 2)
by: jcrouse | last post by:
I am using the following code to move a label on a form at runtime: If myMousedown = lblP1JoyRight.Name Then If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then bTransCk = True lblP1JoyRight.BackColor = clrLabelMove
by: Dean Slindee | last post by:
It appears that I have two routines that don't play well together! First routine: a form's background is shaded with a gradient color. Second routine: then, the background of all labels on the form are made transparent. What results is the label's backcolor appearing as blocks of 'control' colored background. Setting the label's backcolor to color.transparent does not make it transparent (evidently the text is repainted with a...
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text written on the glass pane. i need to be able to see the control or form that is underneath the RichTextbox, and at the same time to be able to write and erase text to the RichTextbox. i'm assuming that it is the backcolor that hides what is...
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background however shows white as the PictureBox moves but I want it to be transparent. The PictureBox BackColor is set to Transparent .. but no affect. I have used PhotoShop to make the image background transparent .. again no affect. If I make the image a...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.