From: Armin Zingler on
Am 02.03.2010 17:11, schrieb zzz:
> "Armin Zingler" <az.nospam(a)freenet.de> ha scritto nel messaggio
> news:eOTQ8GiuKHA.4636(a)TK2MSFTNGP06.phx.gbl...
>
>> Anyway, what's your final goal? There may be simpler ways to achieve it.
>>
> I'd like to replace a kind of controls, for example to have my own skin.
> I can create a mybutton class that inherits by button class, but it s
> different because in the paint event, it redraws the button like I want.
> Doing it for many controls, I can have my customized graphic controls
> The idea was looking at skincrafter.net( dll that allows to cutomize skin
> in windows form, free registering visual studio express), and I wanted to
> create something of similar.
> If I can override the On paint of all my controls, I could easily get it
> .....;)
> Thanks
>

What about always using MyButton class that behaves depending on the skin settings?
So you don't have to replace any controls.


--
Armin
From: zzz on

"Armin Zingler" <az.nospam(a)freenet.de> ha scritto nel messaggio
news:O9T8%23QiuKHA.5036(a)TK2MSFTNGP02.phx.gbl...

> What about always using MyButton class that behaves depending on the skin
> settings?
> So you don't have to replace any controls.
>

Do you mean creating already the form with customized buttons?
Its not my idea....I want to create form in standard mode and if I like, I
want to change skin in runtime :)


From: Armin Zingler on
Am 02.03.2010 18:07, schrieb zzz:
> "Armin Zingler" <az.nospam(a)freenet.de> ha scritto nel messaggio
> news:O9T8%23QiuKHA.5036(a)TK2MSFTNGP02.phx.gbl...
>
>> What about always using MyButton class that behaves depending on the skin
>> settings?
>> So you don't have to replace any controls.
>>
>
> Do you mean creating already the form with customized buttons?

yep. but they can look like default.

> Its not my idea....I want to create form in standard mode and if I like, I
> want to change skin in runtime :)

Replacing controls is a lot of work, but you hardly have to
write anything to make your own controls look like default controls.


--
Armin
From: zzz on

"Armin Zingler" <az.nospam(a)freenet.de> ha scritto nel messaggio
news:evx030iuKHA.4908(a)TK2MSFTNGP06.phx.gbl...

> Replacing controls is a lot of work, but you hardly have to
> write anything to make your own controls look like default controls.
>

Why? it's only some code rows, though I have a problem....could you help me
please?
It replaces a button with mybutton.
Thanks


'-----form1.vb-----------------------------------
Imports System.Reflection
Imports System.IO

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
For Each t As Control In Me.Controls
If t.GetType() Is GetType(Button) Then
Dim a As New MyButton
assegna_proprieta(sender, a)
a.Left = 300
Me.Controls.Remove(sender)
Me.Controls.Add(a)
Me.Invalidate()
End If
Next
End Sub

Public Sub assegna_proprieta(ByRef source_obj As Object, ByRef dest_obj As
Object)
Dim tx As Type = source_obj.GetType()
Dim properties() As PropertyInfo = tx.GetProperties()
For Each prop As PropertyInfo In properties
Dim pi As System.Reflection.PropertyInfo =
dest_obj.GetType().GetProperty(prop.Name)
If pi IsNot Nothing Then
Try
pi.SetValue(dest_obj, prop.GetValue(source_obj, Nothing), Nothing)
Debug.Print(prop.Name & "-> " & prop.GetValue(source_obj, Nothing).ToString)
Catch
' Debug.Print(prop.Name &
"-> ----------------------------------------------------------------")
End Try
End If
Next
End Sub
End Class
'-------mybutton.vb-----------------------------------------------------------------
Public Class MyButton
Inherits Button
Private _clicked As Boolean = False
Protected Overrides Sub OnMouseUp(ByVal mevent As MouseEventArgs)
_clicked = False
MyBase.Invalidate()
Invalidate()
End Sub
Protected Overrides Sub OnMouseDown(ByVal mevent As MouseEventArgs)
_clicked = True
Invalidate()
End Sub
Private Sub MyButton_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If _clicked = True Then
e.Graphics.DrawRectangle(Pens.Aqua, 0, 0, Me.Width, Me.Height)
Else
e.Graphics.DrawRectangle(Pens.Red, 0, 0, Me.Width, Me.Height)
End If
End Sub
End Class


From: Armin Zingler on
Am 03.03.2010 10:24, schrieb zzz:
> "Armin Zingler" <az.nospam(a)freenet.de> ha scritto nel messaggio
> news:evx030iuKHA.4908(a)TK2MSFTNGP06.phx.gbl...
>
>> Replacing controls is a lot of work, but you hardly have to
>> write anything to make your own controls look like default controls.
>>
>
> Why? it's only some code rows, though I have a problem....could you help me
> please?
> It replaces a button with mybutton.


Now I fail to understand your problem. If you want to replace controls
by other controls you must create them and set their properties. You have
to write the code for this. You can do it by passing a Button to the
constructor of your own Button class. The constructor copies some property
values. That's what I already wrote.


.... I see you wrote the code already. Changes see inline.

> Thanks
>
>
> '-----form1.vb-----------------------------------
> Imports System.Reflection
> Imports System.IO
>
> Public Class Form1
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> For Each t As Control In Me.Controls
> If t.GetType() Is GetType(Button) Then
> Dim a As New MyButton
> assegna_proprieta(sender, a)
> a.Left = 300
> Me.Controls.Remove(sender)

Me.Controls.Remove(DirectCast(sender, Control))


> Me.Controls.Add(a)
> Me.Invalidate()
> End If
> Next
> End Sub
>
> Public Sub assegna_proprieta(ByRef source_obj As Object, ByRef dest_obj As
> Object)

Public Sub assegna_proprieta(ByVal source_obj As Object, ByVal dest_obj As Object)

changed: ByRef -> ByVal

IMO the type should be Control, not Object. I'm curious if copying all property
values works. At runtime, using Reflection is more work than explicitly copying
values bit by bit. Anyway, your decision.

Don't know if this solves your problem.

--
Armin
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Writing to text file
Next: Windows Service