|
I will take a look on it and come back later to this Discussion ...
In fact it is very good to have the complete Control - so I could test what is going wrong ...
|
|
|
|
|
OK ... changes made ...
I have deleted all unnecessary content and added all needed content to make it work - you should carefully take a look on it ...!!!
Also the Designer now will store all the changes at the properties inside the class. Perhaps, for later use, you should find a better name for it ...
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Public Class NewPictureBox
Inherits PictureBox
Public Sub New()
Size = New Size(100, 100)
SizeMode = PictureBoxSizeMode.Zoom
End Sub
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
Public ReadOnly Property Properties() As TextLocation
Get
Return Me.m_properties
End Get
End Property
Private WithEvents m_properties As New TextLocation
Private Sub Properties_Changed() Handles m_properties.Changed
Me.Invalidate()
End Sub
Friend Sub NotifyStateChanged(source As TextLocation, propertyName As String)
Me.Invalidate()
Debug.WriteLine("UIListBox: State changed.")
End Sub
Protected Overrides Sub OnResize(ByVal e As EventArgs)
MyBase.OnResize(e)
Size = New Size(Width, Width)
End Sub
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
Dim graph = pe.Graphics
Dim rectContourSmooth = Rectangle.Inflate(ClientRectangle, -1, -1)
Dim rectBorder = Rectangle.Inflate(rectContourSmooth, -m_properties.BorderSize, -m_properties.BorderSize)
Dim smoothSize = If(m_properties.BorderSize > 0, m_properties.BorderSize * 3, 1)
Dim newText = m_properties.Caption
Using borderGColor = New LinearGradientBrush(rectBorder, m_properties.BorderColor, m_properties.BorderColor2, m_properties.GradientAngle)
Using pathRegion = New GraphicsPath()
Using penSmooth = New Pen(Parent.BackColor, smoothSize)
Using penBorder = New Pen(borderGColor, m_properties.BorderSize)
graph.SmoothingMode = SmoothingMode.AntiAlias
penBorder.DashStyle = m_properties.BorderLineStyle
penBorder.DashCap = m_properties.BorderCapStyle
pathRegion.AddEllipse(rectContourSmooth)
Region = New Region(pathRegion)
graph.DrawString(m_properties.Caption, New Font("Segoe UI", 12, FontStyle.Regular), New SolidBrush(Color.Black), m_properties.CaptionLocation.X, m_properties.CaptionLocation.Y, StringFormat.GenericDefault)
graph.DrawEllipse(penSmooth, rectContourSmooth)
If m_properties.BorderSize > 0 Then graph.DrawEllipse(penBorder, rectBorder)
End Using
End Using
End Using
End Using
End Sub
End Class
<TypeConverter(GetType(ExpandableObjectConverter))>
Public Class TextLocation
Public Property Caption As String
Get
Return m_captiontext
End Get
Set(ByVal Value As String)
m_captiontext = Value
OnValueChanged()
End Set
End Property
Private m_captiontext As String = "label"
Overrides Function toString() As String
Return "<" & m_captiontext & ">"
End Function
Property CaptionLocation As Point
Get
Return m_captionx
End Get
Set(ByVal Value As Point)
m_captionx = Value
OnValueChanged()
End Set
End Property
Private m_captionx As New Point(50.0F, 10.0F)
Public Property BorderSize As Integer
Get
Return m_borderSizeField
End Get
Set(ByVal value As Integer)
m_borderSizeField = value
OnValueChanged()
End Set
End Property
Private m_borderSizeField As Integer = 2
Public Property BorderColor As Color
Get
Return m_borderColorField
End Get
Set(ByVal value As Color)
m_borderColorField = value
OnValueChanged()
End Set
End Property
Private m_borderColorField As Color = Color.Blue
Public Property BorderColor2 As Color
Get
Return m_borderColor2Field
End Get
Set(ByVal value As Color)
m_borderColor2Field = value
OnValueChanged()
End Set
End Property
Private m_borderColor2Field As Color = Color.RoyalBlue
Public Property BorderLineStyle As DashStyle
Get
Return m_borderLineStyleField
End Get
Set(ByVal value As DashStyle)
m_borderLineStyleField = value
OnValueChanged()
End Set
End Property
Private m_borderLineStyleField As DashStyle = DashStyle.Solid
Public Property BorderCapStyle As DashCap
Get
Return m_borderCapStyleField
End Get
Set(ByVal value As DashCap)
m_borderCapStyleField = value
OnValueChanged()
End Set
End Property
Private m_borderCapStyleField As DashCap = DashCap.Flat
Public Property GradientAngle As Single
Get
Return m_gradientAngleField
End Get
Set(ByVal value As Single)
m_gradientAngleField = value
OnValueChanged()
End Set
End Property
Private m_gradientAngleField As Single = 50.0F
Private Sub OnValueChanged()
RaiseEvent Changed()
End Sub
Public Event Changed()
Overrides Function toString() As String
Return "<" & "..." & ">"
End Function
End Class
|
|
|
|
|
Wow!
Just seen the email, 1st coffee and this is a great surprise. Very kind of you to fix my issues. I really appreciate your time.
Only thing I found was the following, Visual Studio complained about multiple definitions with identical signatures.
Overrides Function toString() As String
Return "<" & m_captiontext & ">"
End Function so I did this, and it works fantastic.
'Public Overrides Function toString() As String
'Return "<" & "..." & ">"
'End Function
|
|
|
|
|
I'm sorry - but very good if you fixed it by yourself.
It would be glad, when it is working for you, when you rate (upvote) my Solution.
|
|
|
|
|
Another Suggestion for your custom class / Properties - take a look at the Defaultvalue-Attribute :
<DefaultValue("label")>
Public Property Caption As String
Get
Return m_captiontext
End Get
Set(ByVal Value As String)
m_captiontext = Value
OnValueChanged()
End Set
End Property
Private m_captiontext As String = "label"
|
|
|
|
|
Been searching on this subject, as this is still new to me, and I came across those Attributes. This is what I have started to work on.
<DisplayName("Caption"),
DescriptionAttribute("Enter Caption for image"),
ParenthesizePropertyName(False),
XmlElementAttribute("Caption"),
NotifyParentProperty(True),
DefaultValue("label"),
EditorBrowsable(EditorBrowsableState.Always),
RefreshProperties(RefreshProperties.All)> Still looking into this, but it looks nice in the Property Page, to see these appear! Liking where this is going. Again, your help, time and knowledge very much appreciated.
|
|
|
|
|
Since Control-Development is/was one of my favourites I could give a lot of additional tipps - so if you want feel free to ask for ...
Generally what is possible to do :
- delete unused Properties
- switch dependend Properties visible / unvisible
- create Smart-Tags to a Control
- make a Control usable in Designmode
and so on ...
|
|
|
|
|
Very kind my friend.
Here is a list of what i would like to accomplish (if possible)
Custom Picturebox desires
Properties
-BorderItems(heading)
-BorderColor
-BorderColor2
-BorderCapStyle
-BorderGradientAngle
-BorderLineStyle
-BorderSize
-BorderStyle
-CaptionText(heading)
-CaptoinBackColor
-CaptionForeColor
-CaptionFont
-CaptionLocation
-CaptionPlacement (Top or Bottom of Image)
-CaptionText
• (Would like to do the following shapes if possible with the above BorderItems)
• Shapes (picturebox) **see the current function for rounded corners below**
o Hexagon
o Oval
o Round
o RoundCorners
o Square
‘Change to rounded corners, let user pick size and color, currently how i do this in my program now.
'get the current image
Dim StartImage As Image = tmpImage
Dim RoundedImage As Image = ClsPicShapes.RoundCorners(StartImage, value, .ColorBoarders.Color)
Public Shared Function RoundCorners(ByVal StartImage As Image, ByVal CornerRadius As Single, ByVal BackgroundColor As Color) As Image
CornerRadius = (CornerRadius * 2)
Dim RoundedImage As Bitmap = New Bitmap(StartImage.Width, StartImage.Height)
Dim g As Graphics = Graphics.FromImage(RoundedImage)
g.Clear(BackgroundColor)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
Dim brush As Brush = New TextureBrush(StartImage)
Dim gp As GraphicsPath = New GraphicsPath
gp.AddArc(0, -1, CornerRadius, CornerRadius, 180, 90)
gp.AddArc((-1 + (RoundedImage.Width - CornerRadius)), -1, CornerRadius, CornerRadius, 270, 90)
gp.AddArc((-1 + (RoundedImage.Width - CornerRadius)), (-1 _
+ (RoundedImage.Height - CornerRadius)), CornerRadius, CornerRadius, 0, 90)
gp.AddArc(0, (-1 + (RoundedImage.Height - CornerRadius)), CornerRadius, CornerRadius, 90, 90)
g.FillPath(brush, gp)
Return RoundedImage
End Function
|
|
|
|
|
In the Moment I don't see the wuestion in it - but ... when I understood right I made something similar with a Label.
This Label could have also different shapes - (Rounded, Rectangle, Phased, Raised, Sunken and so on).
If you want to do this you should create for each shape an own method which draw it - like you have done for the Rounded part.
The Selection of the Shapes is an Enum which can also easily placed on a Property. Based on this Enum-Property you select the Shape-Painting inside the OnPaint-Method. At the End the OnPaint-Method will become a very big one ...
What we can do, if there are questions or need for discussion, is : you send me the code and I take a look and/or make changes ...
|
|
|
|
|
Message Closed
modified 2-Apr-23 11:45am.
|
|
|
|
|
I noticed your Mail-Adress and will send you a Mail - but now you should imediadly delete your Mail-Adresse out of this discussion ...
|
|
|
|
|
Even better than mine
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks???
if i can get the "OnPaint" to work, i might be able to add rest of the properties!!!
Appreciate the help!
|
|
|
|
|
robert11 wrote: if i can get the "OnPaint" to work, i might be able to add rest of the properties!!!
I don't care about OnPaint; lots of controls don't update in the designer, if you noticed.
The designer would hardly work if realtime painting, that only makes sense for some games and not all.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
appreciate the help!
will try to find how to draw text, move label ect. with out the "OnPaint".
will keep looking for samples to teach me these things!
Have a great night
|
|
|
|
|
FYI
Got it. Took a bit to understand what you meant. I placed some fields on the form, enter some data, x, y locations and button. it prints the text at x,y on the image. Now i can add rest of properties to do forecolor, backcolor, font etc. for caption text. Again, appreciate your help.
|
|
|
|
|
I did not help really, I just pointed in a direction.
You walked that mile, not me.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
do you also have an Example, Eddy ?
I'm interested to see it ...
|
|
|
|
|
No code to copy/paste, and would not be VB either.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
too bad ... I'm everytime interested in other approaches.
I prefer VB ... but C# doesn't matter since we have Telerik ...
Have a nice Sunday
modified 2-Apr-23 6:34am.
|
|
|
|
|
... and thank you very much for your Voting ...
|
|
|
|
|
I was wondering if somebody can point me in the right direction on this
- The goal is to detect when a child form is being moved and read out the current position while moving
-I could use a timer to read out the current position - but at this point I have not been able to fire an event that indicates the form being moved or not ( grabbed by the tool bar that is)
This is just a normal form with standard close minimize / maximize buttons (Not that that should make a difference I assume)
What am I missing ? Any ideas ?
Georg
|
|
|
|
|
You're missing the Form.Move event. All you have to do is handle that event in your form code and you can get the Top and Left property values for the position of the form.
|
|
|
|
|
That's what I thought - unfortunately that event does not fire for me....
Is there a setting in the parent that could prevent that event from firing ?
Georg
|
|
|
|
|
That means there is no code "wiring-up" the event handler.
If you're looking at the position of Form2 from inside Form1 code, you have to "wire up" the event yourself. If you're only looking at the position of Form2 inside Form2 code, the event isn't getting wired up in the Designer code.
Which is it?
|
|
|
|
|