C
C#8mo ago
Spore355

Placeholder property seems to be missing from textbox?

Could someone please inform about any possible reasons as to why this property is missing?
99 Replies
Spore355
Spore355OP8mo ago
I am trying to make a search bar for my Winform app, and I want a placeholder for my search bar so that it is clear to the user what they are interacting with, but the property of the textbox seems to be missing.
Angius
Angius8mo ago
It's called PlaceholderText IIRC
Spore355
Spore355OP8mo ago
I have sorted the properties alphabetically, and it is only displaying PasswordChar
Spore355
Spore355OP8mo ago
This is what I can see
No description
Angius
Angius8mo ago
I wonder if you need to set it with code, for some reason
Spore355
Spore355OP8mo ago
Have you ever had this issue before, or had to do something similar?
Angius
Angius8mo ago
I never used Winforms Well, sorry, once in college I made a shitty calculator with it
Spore355
Spore355OP8mo ago
Ah, I see Do you know of any packages that I can install to add more items to my toolbox? Perhaps I can download a toolbox add on? Does that exist?
Angius
Angius8mo ago
There are nugets with additional Winforms controls, yes $winforms
Angius
Angius8mo ago
Uh, wrong tag Sec
Spore355
Spore355OP8mo ago
Bruh, I swear it's not even that advanced of a project Just a symbol/character library Still, definitely more complicated than anythin i've ever done before Also, what is MODiX?
Angius
Angius8mo ago
It's the bot running on the server And, you are correct, it's not that advanced Not sure why you're asking for 3rd party controls There's no $winformsuilibs tag, alas
Spore355
Spore355OP8mo ago
I am struggling to make it work
Angius
Angius8mo ago
Does the placeholder property not work from code?
Spore355
Spore355OP8mo ago
I don't know how to use that
Angius
Angius8mo ago
Ah Well, might I suggest looking for some Winforms tutorial, then? You should have a .cs file with the code behind the form There, in the constructor probably, you might be able to set whatever properties of any control
Spore355
Spore355OP8mo ago
I have Form1.cs, and Form1.Designer.cs I have been using Form1.cs, but I still don't know how to reference a specific object Like a textbox For the datatables, I just instantiated them in the Form1.cs, and then stacked them on top of eachother to simulate drop down menus, before then linking those to datagridview tables, which are what display my characters Could you recommend something? I have looked at some before, but they never proved to be very useful to my project
Angius
Angius8mo ago
Create a Windows Forms app with C# - Visual Studio (Windows)
Create a Windows Forms app in Visual Studio with C#, add button controls to the form, and run the code to test your application.
Angius
Angius8mo ago
Microsoft documentation is always a good place to start
Spore355
Spore355OP8mo ago
In fact, I was following a winform tutorial before creating this thread asking about the placeholder property, which doesn't seem to exist on my property list Thank you I am still confused as to why that place holder is missing though
Angius
Angius8mo ago
¯\_(ツ)_/¯ Could be you're using an older version of .NET that doesn't have it, could be it's not exposed to the designer, idk
Spore355
Spore355OP8mo ago
What do you mean by being exposed to the designer?
Angius
Angius8mo ago
It's there in the code but not here
Spore355
Spore355OP8mo ago
In the designer code?
Angius
Angius8mo ago
In the TextBox code The TextBox is a class, defined with code
Spore355
Spore355OP8mo ago
Here is some of what I have in my designer
No description
Angius
Angius8mo ago
That class might have a property PlaceholderText This is not the designer, this is the code behind Just so we're clear
Spore355
Spore355OP8mo ago
This is what I see
No description
Angius
Angius8mo ago
It seems this.searchBar is your search bar Try the .CodeBehind property on it
Spore355
Spore355OP8mo ago
Is the designer the page where I can drag and drop things onto the app?
Angius
Angius8mo ago
This is the designer, yes
No description
Spore355
Spore355OP8mo ago
Ah ok Ah, well that's the textbox that I dragged in and labelled searchBar But it currently does not do anything What does this do?
Angius
Angius8mo ago
Uh It's... a property Let me guess, you don't know C#?
Spore355
Spore355OP8mo ago
As I said, I am a beginner Quite inexperienced
Angius
Angius8mo ago
I'd certainly recommend starting with anything that's not a UI application
Spore355
Spore355OP8mo ago
Well, this work is due soon, and I can't really afford to restart Although I would agree with you, this probably was not the best thing for me to choose Although my options were limited
Angius
Angius8mo ago
To answer your question, then, properties are public accessor to the inner state of a class instance
Spore355
Spore355OP8mo ago
I had to us a database for my project, but it was either this, or use a website and use SQLite
Angius
Angius8mo ago
A website would've been easier tbh
Spore355
Spore355OP8mo ago
I think I understand, but would you mind elaborating off of this? Perhaps, although some of my friends have been having a rough time as well
MODiX
MODiX8mo ago
Angius
REPL Result: Success
public class MyCoolTextbox
{
public string PlaceholderText { get; set; }

public void Show()
{
Console.WriteLine($"Enter whatever: [{PlaceholderText}]");
}
}

var tb = new MyCoolTextbox();
tb.PlaceholderText = "unga bunga";
tb.Show();
public class MyCoolTextbox
{
public string PlaceholderText { get; set; }

public void Show()
{
Console.WriteLine($"Enter whatever: [{PlaceholderText}]");
}
}

var tb = new MyCoolTextbox();
tb.PlaceholderText = "unga bunga";
tb.Show();
Console Output
Enter whatever: [unga bunga]
Enter whatever: [unga bunga]
Compile: 493.486ms | Execution: 43.467ms | React with ❌ to remove this embed.
Spore355
Spore355OP8mo ago
OOP?
Angius
Angius8mo ago
Yes C# is an object-oriented language
Spore355
Spore355OP8mo ago
Damn, I had a really good OOP program that I made a while ago But when I sent my laptop in for repair, I didn't save it on a USB, so lost it By accident of course And now I can't remember how that stuff works
Angius
Angius8mo ago
Use Github in future Free backup and versioning with Git
Spore355
Spore355OP8mo ago
I always have syncing issues What is is called when your variable tb references mycooltextbox? I have used that to make datatables? Also, can you make a new object by using var?
Angius
Angius8mo ago
tb holds a reference to that instance of MyCoolTextbox var is for type inference
Spore355
Spore355OP8mo ago
I thought var was for variable declaration
Angius
Angius8mo ago
It's the "figure out what type this is" type
Person p = new Person();
var p = new Person();
Person p = new();
Person p = new Person();
var p = new Person();
Person p = new();
are all eqivalent declarations They all do the exact same thing
Spore355
Spore355OP8mo ago
I see What do you mean by saying it holds a reference? Do you mean that it carries the same attributes as the parent class? And that tb is the child subclass?
Angius
Angius8mo ago
The instance is stored on the 1782th shelf tb holds shelf:1782 A reference to where the instance of that class is in memory Not the instance itself Nor a copy of that instance
Spore355
Spore355OP8mo ago
Could you please expand your explanation? And also, what is the relevance of shelf:1782?
Angius
Angius8mo ago
A computer memory is a set of boxes Each box has a number
Spore355
Spore355OP8mo ago
Yes I know this
Angius
Angius8mo ago
The instance of the class is placed in one of those boxes
Spore355
Spore355OP8mo ago
You are talking about address locations in memory
Angius
Angius8mo ago
The variable stores the number of that box
Spore355
Spore355OP8mo ago
Got it Wait hold up I thought that the box stores the variable?
Angius
Angius8mo ago
That's why we can do
MODiX
MODiX8mo ago
Angius
REPL Result: Success
class Foo
{
public int Bar { get; set; }
}

var a = new Foo();
a.Bar = 69;
var b = a;
var c = b;
var d = c;
d.Bar = 420;

a.Bar
class Foo
{
public int Bar { get; set; }
}

var a = new Foo();
a.Bar = 69;
var b = a;
var c = b;
var d = c;
d.Bar = 420;

a.Bar
Result: int
420
420
Compile: 321.592ms | Execution: 34.129ms | React with ❌ to remove this embed.
Angius
Angius8mo ago
a, b, c, and d all store a reference to the same box
Spore355
Spore355OP8mo ago
I am confused with the output of this program If b references a, c references b, and d references c, then why are a and d different?
Angius
Angius8mo ago
They do not reference each other They store the same reference The value of a is, say, box18 Then, we assign that value to variable b, now it also holds box18 And so on References themselves are not passed by reference, if that makes sense
Spore355
Spore355OP8mo ago
Indirect addressing?
Angius
Angius8mo ago
The number of the box is not stored in a box Direct a, b, c, and d store the exact same reference to the exact same place in memory
Spore355
Spore355OP8mo ago
??? Ok, so why is a.Bar = 69, and d.bar = 420, but then a.Bar outputs 420?
Angius
Angius8mo ago
Because d stores the same reference So we go to box 18 Take what's inside And change it's Bar
Spore355
Spore355OP8mo ago
Ok, so does .Bar change what is inside of the memory box?
Angius
Angius8mo ago
Yes That's how all classes work
Spore355
Spore355OP8mo ago
Why did you call it Bar?
Angius
Angius8mo ago
No reason Could be whatever
Spore355
Spore355OP8mo ago
Ok So you were running that function relative to the variable a?
MODiX
MODiX8mo ago
Angius
REPL Result: Success
class UngaBunga
{
public int Xyzzyx { get; set; }
}

var a = new UngaBunga();
a.Xyzzyx = 69;
var b = a;
var c = b;
var d = c;
d.Xyzzyx = 420;

a.Xyzzyx
class UngaBunga
{
public int Xyzzyx { get; set; }
}

var a = new UngaBunga();
a.Xyzzyx = 69;
var b = a;
var c = b;
var d = c;
d.Xyzzyx = 420;

a.Xyzzyx
Result: int
420
420
Compile: 331.821ms | Execution: 33.981ms | React with ❌ to remove this embed.
Spore355
Spore355OP8mo ago
Thus taking up space complexity of 2 for that function? Similar to how a merge sort works, except it just creates 2 copies?
Angius
Angius8mo ago
There are no copies
Spore355
Spore355OP8mo ago
Ok I have another question
Angius
Angius8mo ago
There's only one instance of Foo
Spore355
Spore355OP8mo ago
What is the difference between a class and a function Fundamentally I know that they are very different But what are their different use cases ? Being used on a.Xyzzyx and d.Xyzzyx?
Angius
Angius8mo ago
Both a and d reference the same box, with the same instance
Spore355
Spore355OP8mo ago
Oh Oh Oh Damnit Yes I am being a fool And so do b and c? Also, what is the point of using the getter and setter? When there isn't a getter or setter written into the code?
Angius
Angius8mo ago
No description
Angius
Angius8mo ago
The getter and setter still runs It's just syntactic sugar over getter and setter functions from lesser languages That a.Bar = 1 runs the setter And a.Bar runs the getter $getsetdevolve
MODiX
MODiX8mo ago
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
class Foo
{
private int _bar;

public int GetBar()
{
return _bar;
}

public void SetBar(int bar)
{
_bar = bar;
}
}
can be shortened to
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
class Foo
{
private int _bar;

public int GetBar() => _bar;

public void SetBar(int bar) => _bar = bar;
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}
can be shortened to
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}
can be shortened to
class Foo
{
public int Bar { get; set; }
}
class Foo
{
public int Bar { get; set; }
}
Angius
Angius8mo ago
A function (or a method as we call them in C#) is something an object can do, a class describes what that object is
Spore355
Spore355OP8mo ago
I see That makes sense But what is the point of making bar go to _bar?
Angius
Angius8mo ago
In this particular example? No point But you have some logic in the setter So until we get the field keyword, you will need a backing field That way the property doesn't have to reference itself
Spore355
Spore355OP8mo ago
What do you mean by the field keyword? And why would the property references itself?
Angius
Angius8mo ago
Ah, sorry, I got this thread mixed up with another one Nevermind what I said lol But, yeah, in the case above there's no point having a backing field But if you want to have some logic, it's a must
Spore355
Spore355OP8mo ago
Ok, but why? Is it to do with private and public variable types?
Angius
Angius8mo ago
private string _name;
public string Name {
get => _name;
set => _name = value.ToUpper().Trim();
}
private string _name;
public string Name {
get => _name;
set => _name = value.ToUpper().Trim();
}
This, you cannot do without a _name field
public string Name {
get => Name;
set => Name = value.ToUpper().Trim();
}
public string Name {
get => Name;
set => Name = value.ToUpper().Trim();
}
This would cause an endless loop
Spore355
Spore355OP8mo ago
Because you would change the original value, which is not what you want to do?
Angius
Angius8mo ago
Getting from the property would call the getter, which would attempt to get from the property which would call the getter, and so on ad infinitum
Spore355
Spore355OP8mo ago
How come? Oh Ok That makes sense Hence why you need to make a new variable
Angius
Angius8mo ago
Basically, a
public string GetName()
{
return GetName();
}
public string GetName()
{
return GetName();
}
Spore355
Spore355OP8mo ago
And assign it the same value
Angius
Angius8mo ago
Infinite recursion
Spore355
Spore355OP8mo ago
Yes Thank you for the help you have given me
Angius
Angius8mo ago
Anytime
Want results from more Discord servers?
Add your server