|
Man, You are BIG!
|
|
|
|
|
Hi,
In this program there are 6 pictureboxes and i want to make the now if i keep and transparent image in picturebox then i should be able to see the contents of picturebox1 and picturebox2 and the form, whichever portion of image is transparent the image behind should be visible, i am missing something, please help me
This is my code
Public Class Form1
Dim SelectObj As Object
Dim RecWidth, RecHeight, Rect, RecLeft As Integer
Private handleSize As Integer = 5
Private overHandle As Boolean
Private inPB As Boolean = False
Private resizing As Boolean = False
Private rc1 As Rectangle
Private rc2 As Rectangle
Private rc3 As Rectangle
Private rc4 As Rectangle
Private startPoint As Point
Private endPoint As Point
Private lastPoint As Point
Private screenRC As Rectangle
Public OldLeft As Integer
Public OldTop As Integer
Public startX, startY As Integer
Dim tpVal As Single = 1.0F
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.BackColor = Color.Transparent
PictureBox2.BackColor = Color.Transparent
PictureBox3.BackColor = Color.Transparent
PictureBox4.BackColor = Color.Transparent
PictureBox5.BackColor = Color.Transparent
PictureBox6.BackColor = Color.Transparent
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox2.BorderStyle = BorderStyle.FixedSingle
PictureBox3.BorderStyle = BorderStyle.FixedSingle
PictureBox4.BorderStyle = BorderStyle.FixedSingle
PictureBox5.BorderStyle = BorderStyle.FixedSingle
' PictureBox6.BorderStyle = BorderStyle.FixedSingle
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim frm1 As New MyForm
'frm1.Show()
PictureBox1.Parent = Me
PictureBox2.Parent = Me
PictureBox3.Parent = Me
PictureBox4.Parent = Me
PictureBox5.Parent = Me
PictureBox6.Parent = Me
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click
SelectObj = DirectCast(sender, PictureBox)
End Sub
Private Sub BringToFrontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BringToFrontToolStripMenuItem.Click
SelectObj.BringToFront()
End Sub
Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter, PictureBox2.MouseEnter, PictureBox3.MouseEnter, PictureBox4.MouseEnter, PictureBox5.MouseEnter, PictureBox6.MouseEnter
UpdateHandles()
inPB = True
DirectCast(sender, PictureBox).Refresh()
SelectObj = DirectCast(sender, PictureBox)
Me.TransparencyKey = Color.Red
End Sub
Private Sub UpdateHandles()
On Error Resume Next
rc1 = New Rectangle(0, 0, handleSize, handleSize)
rc2 = New Rectangle(0, SelectObj.Height - handleSize - 2, handleSize, handleSize)
rc3 = New Rectangle(SelectObj.Width - handleSize - 2, 0, handleSize, handleSize)
rc4 = New Rectangle(SelectObj.Width - handleSize - 2, SelectObj.Height - handleSize - 2, handleSize, handleSize)
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint, PictureBox2.Paint, PictureBox3.Paint, PictureBox4.Paint, PictureBox5.Paint, PictureBox6.Paint
If inPB Then
e.Graphics.FillRectangle(Brushes.Red, rc1)
e.Graphics.FillRectangle(Brushes.Red, rc2)
e.Graphics.FillRectangle(Brushes.Red, rc3)
e.Graphics.FillRectangle(Brushes.Red, rc4)
End If
SelectObj = DirectCast(sender, PictureBox)
' ControlPaint.DrawReversibleFrame(New Rectangle(RecLeft, Rect, RecWidth - 2, RecHeight - 2), Color.Cyan, FrameStyle.Thick)
'Me.RectangleToScreen(New Rectangle(0, 0, RecWidth, RecHeight))
' e.Graphics.DrawRectangle(Pens.Black, New Rectangle(RecLeft, Rect, RecWidth, RecHeight))
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown, PictureBox2.MouseDown, PictureBox3.MouseDown, PictureBox4.MouseDown, PictureBox5.MouseDown, PictureBox6.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left AndAlso overHandle Then
resizing = True
If rc1.Contains(e.X, e.Y) Then
startPoint = New Point(DirectCast(sender, PictureBox).Width, DirectCast(sender, PictureBox).Height)
endPoint = New Point(0, 0)
ElseIf rc2.Contains(e.X, e.Y) Then
startPoint = New Point(DirectCast(sender, PictureBox).Width, 0)
endPoint = New Point(0, DirectCast(sender, PictureBox).Height)
ElseIf rc3.Contains(e.X, e.Y) Then
startPoint = New Point(0, DirectCast(sender, PictureBox).Height)
endPoint = New Point(DirectCast(sender, PictureBox).Width, 0)
ElseIf rc4.Contains(e.X, e.Y) Then
startPoint = New Point(0, 0)
endPoint = New Point(DirectCast(sender, PictureBox).Width, DirectCast(sender, PictureBox).Height)
End If
lastPoint = New Point(e.X, e.Y)
' screenRC = PictureBox1.RectangleToScreen(NormalizedRC(startPoint, endPoint))
' ControlPaint.DrawReversibleFrame(screenRC, PictureBox1.BackColor, FrameStyle.Dashed)
Else
startX = e.X
startY = e.Y
End If
SelectObj = DirectCast(sender, PictureBox)
' ControlPaint.DrawReversibleFrame(New Rectangle(RecLeft, Rect, RecWidth - 2, RecHeight - 2), Color.Cyan, FrameStyle.Thick)
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove, PictureBox2.MouseMove, PictureBox3.MouseMove, PictureBox4.MouseMove, PictureBox5.MouseMove, PictureBox6.MouseMove
overHandle = rc1.Contains(e.X, e.Y) OrElse rc2.Contains(e.X, e.Y) OrElse rc3.Contains(e.X, e.Y) OrElse rc4.Contains(e.X, e.Y)
If resizing Then
' ControlPaint.DrawReversibleFrame(screenRC, PictureBox1.BackColor, FrameStyle.Dashed)
endPoint.X = endPoint.X + (e.X - lastPoint.X)
endPoint.Y = endPoint.Y + (e.Y - lastPoint.Y)
lastPoint = New Point(e.X, e.Y)
screenRC = PictureBox1.RectangleToScreen(NormalizedRC(startPoint, endPoint))
ControlPaint.DrawReversibleFrame(screenRC, PictureBox1.BackColor, FrameStyle.Dashed)
ElseIf e.Button = Windows.Forms.MouseButtons.Left Then
DirectCast(sender, PictureBox).Location = New Point(DirectCast(sender, PictureBox).Left - (startX - e.X), DirectCast(sender, PictureBox).Top - (startY - e.Y))
End If
' ControlPaint.DrawReversibleFrame(New Rectangle(RecLeft, Rect, RecWidth - 2, RecHeight - 2), Color.Cyan, FrameStyle.Thick)
SelectObj = DirectCast(sender, PictureBox)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp, PictureBox2.MouseUp, PictureBox3.MouseUp, PictureBox4.MouseUp, PictureBox5.MouseUp, PictureBox6.MouseUp
If resizing Then
resizing = False
' ControlPaint.DrawReversibleFrame(screenRC, DirectCast(sender, PictureBox).BackColor, FrameStyle.Dashed)
Dim newPosition As Rectangle = Me.RectangleToClient(DirectCast(sender, PictureBox).RectangleToScreen(NormalizedRC(startPoint, endPoint)))
DirectCast(sender, PictureBox).SuspendLayout()
DirectCast(sender, PictureBox).Location = newPosition.Location
DirectCast(sender, PictureBox).Size = newPosition.Size
DirectCast(sender, PictureBox).ResumeLayout()
UpdateHandles()
' PictureBox1.Image = MakePicSmall(PictureBox3, newPosition.Width, newPosition.Height, True)
DirectCast(sender, PictureBox).Refresh()
End If
' ControlPaint.DrawReversibleFrame(New Rectangle(RecLeft, Rect, RecWidth - 2, RecHeight - 2), Color.Cyan, FrameStyle.Thick)
SelectObj = DirectCast(sender, PictureBox)
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave, PictureBox2.MouseLeave, PictureBox3.MouseLeave, PictureBox4.MouseLeave, PictureBox5.MouseLeave, PictureBox6.MouseLeave
inPB = False
DirectCast(sender, PictureBox).Refresh()
ControlPaint.DrawReversibleFrame(New Rectangle(RecLeft, Rect, RecWidth - 2, RecHeight - 2), Color.Cyan, FrameStyle.Thick)
SelectObj = DirectCast(sender, PictureBox)
End Sub
Private Function NormalizedRC(ByVal ptA As Point, ByVal ptB As Point) As Rectangle
Return New Rectangle(Math.Min(ptA.X, ptB.X), Math.Min(ptA.Y, ptB.Y), Math.Abs(ptA.X - ptB.X), Math.Abs(ptA.Y - ptB.Y))
End Function
Private Function GetImage() As Image
Dim filname As String
OpenFileDialog1.ShowDialog()
filname = OpenFileDialog1.FileName
Return Image.FromFile(filname)
End Function
Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick, PictureBox2.DoubleClick, PictureBox3.DoubleClick, PictureBox4.DoubleClick, PictureBox5.DoubleClick, PictureBox6.DoubleClick
DirectCast(sender, PictureBox).Image = GetImage()
DirectCast(sender, PictureBox).SizeMode = PictureBoxSizeMode.AutoSize
End Sub
Private Sub ApplyMaskToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApplyMaskToolStripMenuItem.Click
' SelectObj.image = ProcessImageMask(SelectObj.image)
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
tpVal = CSng(TrackBar1.Value) / 10
Me.Invalidate()
End Sub
End Class
can any one solve this problem
thanks
dsd
|
|
|
|
|
It's useful f or me ,thank you!
|
|
|
|
|
It seems not to work in Classic Style. I can't find a solution for this problem, because the problem doesn't let it debug...any suggestions?
With kind regards,
R.M.W.M. van der Enden B.Sc.
|
|
|
|
|
Sorry, but could you be more specific please.
rvdenden wrote: It seems not to work in Classic Style
What does not work?
When you set flat style to Standard you get the Old Windows 98 style with transparency, and when set to System you get the Windows XP style with transparency.
I don't see any problem.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
When I run the application above (the VB one) everythong works fine but when I switch my pc to Windows Classic view, the application traps immediately. By then aI get the next errormessage:
---
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.windows.forms.dll
Additional information: Index was outside the bounds of the array.
---
I hope you can do something with this information.
With kind regards,
R.M.W.M. van der Enden
|
|
|
|
|
The c# version works because I put different code in it. opps. I thought it was the same.
There is one change required in the customColors.vb
There is a select case statement at line 72
<br />
Select Case sbColor.ToString.ToUpper.Trim<br />
Case "NORMALCOLOR"<br />
Return CustomColors.NormalColor<br />
Case "HOMESTEAD"<br />
Return CustomColors.HomeStead<br />
Case "METALLIC"<br />
Return CustomColors.Metallic<br />
End Select<br />
This needs a default case adding to it. The following default case will match the c# version.
<br />
Case Else<br />
Return CustomColors.Metallic<br />
With the themes on in code, supported by the opperating system, but off in the display properties the api call for the current theme returns an empty string. This is fixed in .Net 2.0 as you no longer need to call the api direct as it is wrapped up for you in the System.Windows.Forms.VisualStyles namespace. This then allows you to test for the themes being supported but turned off.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
I have just been working on a .Net 2.0 project that required a checkbox and I discovered the exact same problem still exists in 2.0!
I also found that the orange box on my upgraded code did not draw in the orange box when the mouse was over the control. The following code fixed that problem in VB.net.
<br />
Protected Overrides Sub OnMouseHover(ByVal e As System.EventArgs)<br />
MyBase.OnMouseHover(e)<br />
If Me._FlatStyle.Equals(FlatStyle.System) Then<br />
Dim graph As Graphics = Me.CreateGraphics<br />
DrawingHelper.DrawCheckBox(graph, _<br />
Me.GetCheckBoxRectangle(), True, Me.CheckState)<br />
graph.Dispose()<br />
End If<br />
End Sub<br />
Interestingly also I found that the combobox only themed correctly in blue or Olive themes. Metallic returns the blue theme colour of border!
When will Microsoft fix these theming problems!
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Am I missing something here? Just setting the BackColor property to Color.Transparent seems to work just fine for me. This is with VS.Net 2003.
-- modified at 13:02 Saturday 31st December, 2005
Actually forget this. I didn't notice that you were changing the .FlatStyle to System, then it doesn't work!
|
|
|
|
|
:-> Cool, finally an easy way to achieve what i was looking for : Transparent Labels.
Here i post the code (Really similar to the one provided for the checkbox )
<br />
Imports System<br />
Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.ComponentModel<br />
<br />
<ToolboxBitmapAttribute(GetType(CheckBox))> _<br />
Public Class CustomLabel : Inherits Label<br />
<br />
<br />
' Methods<br />
Public Sub New()<br />
<br />
MyBase.New()<br />
Me.SetDefaultControlStyles()<br />
Me.customInitialisation()<br />
<br />
End Sub<br />
<br />
Private Sub SetDefaultControlStyles()<br />
<br />
Me.SetStyle(ControlStyles.DoubleBuffer, True)<br />
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)<br />
Me.SetStyle(ControlStyles.ResizeRedraw, True)<br />
Me.SetStyle(ControlStyles.UserPaint, True)<br />
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)<br />
<br />
End Sub<br />
<br />
<DefaultValueAttribute(GetType(System.Drawing.Color), "Transparent")> _<br />
Public Overrides Property BackColor() As System.Drawing.Color<br />
Get<br />
Return MyBase.BackColor<br />
End Get<br />
Set(ByVal Value As System.Drawing.Color)<br />
MyBase.BackColor = Value<br />
End Set<br />
End Property<br />
<br />
Private Sub customInitialisation()<br />
<br />
Me.SuspendLayout()<br />
<br />
Me.BackColor = Color.Transparent<br />
<br />
Me.ResumeLayout(False)<br />
<br />
End Sub<br />
End Class
|
|
|
|
|