❔ How can I make it where I'm able to change the colour of the text
When the user starts the program they need to pick a colour for the text called "Visual C#"
80 Replies
no idea what this means
sorry for my bad english but
I'm trying to make it were when the user clicks "start" they'll have an option to change a color of the text
like this
You're on the right track, however BackColor is the background color.
If you want to change the color of the drawn text, you need to apply it to the brush and redraw
so should it be "Brushes.Forecolor"?
Where is the brushes class from? The one in System.Windows.Media has no such property
here's all the code rn
I was thinking of grabbing "this.ForeColor = pickcolor.Color;"
and then putting in on "Brushes.b"
Just trying to find the Brushes class you're using to check the docs
Normally you create a Brush instance and use that
Where is that class from when you hover the name?
Found it https://learn.microsoft.com/en-us/dotnet/api/system.drawing.brushes?view=windowsdesktop-7.0
Brushes Class (System.Drawing)
Brushes for all the standard colors. This class cannot be inherited.
That's a static class though, doesn't make sense to have as a member
I'm confused
same
Anyway, the proper way of doing it is declaring b as Brush, not Brushes
oh
wait for this code a color picker pops-up and you can pick any color you want
I wan't to use this code but for
for this
Set the Brush's color to the picker color
g.DrawString(..., b, ...);
B = this.ForeColor = pickcolor.Color;
something like this?
yes, though Brush should be initialized as a new SolidBrush
new SolidBrush??
Reference types are null by default
var b = new SolidBrush();
is var just brush??
Or
SolidBrush b = new()
since it's a class member
var
is a shortcut that determines the type based on the value given but doesn't work for declaring members, only variables
so jsut SolidBrush b = new(someColor)
at the class level to reuse it*
Then when the color changes you can set the Color property of the brushYou need to specify a color too
but the color could be anything tho
But you know what it is when it reaches that line
The color in new() can also be a variable or property 🙂
man I'm soo confused 💀
I'm soo sorry
Color is a type so you can have say
Color red = Color.Red
or Color red = Color.FromArgb(0, 255, 0, 0)
or in this case, Color selection = pickColor.Color
wait
this is a System.Drawing.Color??
but I want to convert it to
yes
brush
Brush is System.Drawing.Brush
here's the entire code
SolidBrush has a Color property of type System.Drawing.Color which you also need to create the brush
the "brush" is this > SolidBrush b = new();
yes
But you need to specify the color in new()
I did
as a Color, not a string
I tried doing new("blue")
like Color.Blue?
or just
Blue
With
pickColor.Color
inside the ()
yes
mb you defined it as pickcolor
no uppercase
What does the error say?
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
our teach told us to use "Windos Forms App (.NET Framework)
For now, just put
new SolidBrush(colorHere)
nvm
nvm
Yeah many do that. Mostly just a case or 1. Textbooks not being up to date and 2. Computer labs potentially not having 5+ installed
quick question I can delete everything here?
v
That should work
@TheBoxyBear BRO I LOVE YOU
But don't forget to dispose of the brush afterwards, or do it automatically with using
what do you mean?
(using SolidBrush b = new...) {// use the brush}
or calling b.Dispose()
after drawingI'm still confused 💀
To release the resources used by the Brush. If there's a Dispose, you most likely need to call it when you're done with the object
In more recent versions of c#, you can simply the using syntax to just be
using Type name = new...;
with no brackets.oh
OH MY GOD I'm stupid
when the form loads
a color picker should pop up first
and then after that
the forms loads with the text 💀
I'm not gonna fix it
@TheBoxyBear Thanks for the help
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.