|
You'd need to "Create" labels, and add them to the controls-collection of the form in order to get some labels on the form.
for (i = 0; i < icons.Count; i++)
{
Label l = new Label () { Dock = DockStyle.Top };
this.Controls.Add(l);
l.Text = icons[i];
} I've changed it from "tag" to "text", so you can see what character from the list is being loaded into the label. The "tag" property itself does not change the appearance of a label. Take note that "l" is a local variable; it won't be used outside the constructor, limits the scope and is preferable over a member-variable in this scenario.
Further, you'd only need a single random; at the moment you're creating a rnd-object in two separate places. Lastly; if you want pictures, then a PictureBox control may be preferable over a Label.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for answering. I do have 16 labels already on the form and What I'm doing is a picture matching game with wingding symbols on the text AND the tag properties. So when i click on the label it shows the tag property. Everything works except loading random wingdings in the tag properties. This code handles the clicked picture:
private void Picture_Click(object sender, EventArgs e)
{
if (tmr_Delay.Enabled == true)
return;
Clicked_Picture = (Label)sender;
Clicked_Picture.Enabled = false;
Number_of_Images++;
if (Number_of_Images < 3)
{
Clicked_Picture.Text = Clicked_Picture.Tag.ToString();
if (Number_of_Images == 1)
{
Temp_Tag = Clicked_Picture.Tag.ToString();
Temp_Pic = Clicked_Picture;
}
else
{
if (Temp_Tag != Clicked_Picture.Tag.ToString())
{
tmr_Delay.Enabled = true;
}
else
{
Num_Correct++;
lbl_Matches.Text = Num_Correct.ToString();
if (Num_Correct == 8)
{
timer1.Stop();
MessageBox.Show("Congratulations, all matches complete! \nYou completed the game in " + mins + "m " + secs + "s");
txtUsername.Visible = true;
button1.Visible = true;
lblusername.Visible = true;
lblprompt.Visible = true;
}
}
Number_of_Images = 0;
}
}
}
|
|
|
|
|
Ah, that's because it is not assigning the values it reads correctly. If you use my version, it'll put it in the tags of the controls that are created in that method - but won't hook up the clicked method.
It is below line that assigns the content of the list;
Clicked_Picture.Tag = icons[i];
It is assigned to a "New Label" in the original code. It should point to one of the existing labels. Try looking for one of the existing labels in the constructor, before assigning the value to the tag-property.
Clicked_Picture = this.Controls.Find(string.Format("Label{0}", i), true).FirstOrDefault() as Label;
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your help. What i did in the end was put the labels into a groupbox and assign random locations
List points = new List();
private void Form1_Load(object sender, EventArgs e)
{
foreach (Label label in groupBox1.Controls)
{
points.Add(label.Location);
}
foreach (Label label in groupBox1.Controls)
{
int next = rnd.Next(points.Count);
Point p = points[next];
label.Location = p;
points.Remove(p);
}
modified 11-Feb-15 7:59am.
|
|
|
|
|
|
I use below code to reach the autocomplete in a textbox. But the chance is once, it cannot keep in autocomplete status. When I finish an autocomplete work, and then I cannot key in another autocomplete word. Does somebody know how to let textbox always keep in autocomplete?
private void Form1_Load(object sender, EventArgs e)
{
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
});
var textBox = new TextBox
{
AutoCompleteCustomSource = source,
AutoCompleteMode =
AutoCompleteMode.SuggestAppend,
AutoCompleteSource =
AutoCompleteSource.CustomSource,
Location = new Point(20, 20),
Width = ClientRectangle.Width - 40,
Visible = true
};
Controls.Add(textBox);
}
modified 10-Feb-15 8:18am.
|
|
|
|
|
I think your problem is that the text isn't highlighted when you go back into the textbox, so any characters you start to type are appended to what is already there - hence auto-complete does not work.
The solution is to highlight all of the text as you enter the textbox: Add this line just before you add textbox to the Controls collection
textBox.Enter += new System.EventHandler(this.textBox_GotFocus);
and add this method to the form
private void textBox_GotFocus(object sender, EventArgs e)
{
((TextBox)sender).SelectAll();
}
Unfortunately when you use the mouse to enter the field the caret is positioned wherever the mouse pointer is so the MouseEnter method doesn't work in quite the same way as we'd like.
To get over that you can use the MouseClick event:
textBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseClick); and add this method
private void textBox_MouseClick(object sender, MouseEventArgs e)
{
((TextBox)sender).SelectAll();
}
|
|
|
|
|
Hello CHill60! Thanks your answer. But my problem is that I cannot input the second word with Autocomplete list item. For example, when I input "May Apr", it should be disapeear "May April" for me to select "April". Now it just can work in frist word "May".
|
|
|
|
|
That's because May April is not part of the autocomplete list - you'll either have to ensure that all combinations are in the autocomplete list, or write a user control to do that - I'll have another look
|
|
|
|
|
I am working on repeater I use the check box control in header and tbody i want when i check the header check box the all check boxes which is in body checked some body help me how is possible.
|
|
|
|
|
You just asked the same question yesterday - got some answers too...If those answers are not good for you than add details and ask for more info, but asking the same question over and over again is not a good way to getting answers...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi!
I have defined an event in a certain class:
public class BrokenPackageReceivedEventArgs : EventArgs
{
private readonly byte[] package;
public byte[] Package { get { return package; } }
public BrokenPackageReceivedEventArgs(byte[] _package) { package = _package; }
}
public event EventHandler<BrokenPackageReceivedEventArgs> BrokenPackageReceived;
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
It seems that if no method is added to the event, it throws a NullReferenceException. I dont want that exception to occur, in fact I am baffled it actually does occur. Is this really the way events always do if no method is attached? Should I just use a try-catch with an empty catch to get rid of it, or am I missing something?
|
|
|
|
|
I just realized I can do like this:
if(BrokenPackageReceived != null)
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
Is this the common way to do it?
|
|
|
|
|
Yes it is. And you could improve it a bit further by making a copy of it before you check it for null:
var copy = BrokenPackageReceived;
if(copy != null)
copy(this, new .....);
..because theoretically some subscriber could unsubscribe during the execution of the null-check.
edit: to clarify, not some subscriber but the last subscriber
|
|
|
|
|
Rather than doing this, try this:
var handler = BrokenPackageReceived;
if (handler != null)
{
handler(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray());
} The reason you will want to do this is that there's a potential race condition because it's possible for BrokenPackageReceived to have a value when you check it, and then be null when you attempt to call it.
|
|
|
|
|
I have set .net Trust level to medium from Full. Its not allowing me to upload file .
can i change web config trust level to full at the same time when i set .net trust level to medium in IIS.
Will it effect IIS settings and fulfill the purpose of medium trust level.
i go through many articles somewhere its written to allow permission and somewhere set to full in web config.
its showing this error when my project is deployed in root folder else working fine .
Please Help.
Thanks
-- modified 11-Feb-15 0:31am.
|
|
|
|
|
Hello everyone,I have given a million records in sql server and asked apply the Jaro - winkler algorithm to find the dupes in those records and I wanted to do it using c#.net. Could anyone help me if you already did such kind of job.I am a fresher so I need some little help in doing it. I would appreciate for your valuable help .
|
|
|
|
|
Help with what exactly?
If you were looking for someone to just hand over their code, you've come to the wrong site.
|
|
|
|
|
|
As a sidenote; it will find "similar" result, not duplicates.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Is it possible NOT to open the EXE itself and opening instead from within my application only.
What I mean is: I want to launch the WinApplication2 from my WinApplication1 but I don't want the user to go to the windows folder and be able to launch the WinApplication2 direcrly.
Technology News @ www.JassimRahma.com
|
|
|
|
|
Without applying security policies, you cannot prevent the user from being able to launch an application directly. The ability to arbitrarily deny the ability to launch an application would recommend a massive security risk.
|
|
|
|
|
No, you can't prevent someone from launching the other EXE.
Why? Because when a application is launched it's launched AS THE PERSON WHO LAUNCHED IT. This means the process inherits all the security permissions (called a security token) of the account that launched it. Any other process that this process launches also inherits the security token. When your first process launches a second one, it's doing it the exact same way you would. If you try to deny users from launching the second process independently of the first process, your first process won't be able to launch the second process either.
There is a way around this though. In your second process code, check to see if the first process is already running. If not, immediately quit the application.
|
|
|
|
|
Generate two Guids from App1. Start App2 and give on of the guids as a switch. Send the other using TCP/IP, a pipe or a Memory-mapped file.
Shouldn't be too hard to break though (using ILSpy).
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to select all check boxes in Repeater when I select the Header check box like a g mail trash work
|
|
|
|