Reputation:
I'd like to create a custom colors in my "GlobalColors.vb" module with sample code below;
Public Mycolor1 As Object = System.Drawing.Color.FromArgb(30, 155, 0, 144)
I tried to implement this in one of my panel.
Me.Panel1.BackColor = Mycolor1
Me.Panel1.Location = New System.Drawing.Point(54, 47)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(200, 100)
Me.Panel1.TabIndex = 0
But i have an error like below;
Could not find type 'TestApp.GlobalColors'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.
Could anyone know how to define custom colors and use them in background of panels and other WinForm Control elements?
Upvotes: 0
Views: 6879
Reputation: 884
If you had Option Strict On
you would find an error here: Me.Panel1.BackColor = Mycolor1
Error:
Option Strict On disallows implicit conversions from 'Object' to 'Color'.
Change:
Public Mycolor1 As Object = System.Drawing.Color.FromArgb(30, 155, 0, 144)
to:
Public Mycolor1 As Color = System.Drawing.Color.FromArgb(30, 155, 0, 144)
Whether that fixes your original problem I'm not sure, but worth a try.
Upvotes: 0
Reputation: 39132
As described, it works fine for me. You either have a corrupt setup, or you've described it inaccurately:
Module GlobalColors
Public Mycolor1 As Object = System.Drawing.Color.FromArgb(30, 155, 0, 144)
End Module
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Panel1.BackColor = Mycolor1
End Sub
End Class
Upvotes: 1