Click here to Skip to main content
14,575,143 members

Comments by Peter Vegter (Top 34 by date)

Peter Vegter 29-Oct-19 14:13pm View
Thank you, Richard. I just didn't check the message to me properly.
Peter Vegter 26-Oct-19 15:01pm View
Thanks Nelek!
I've tested the solution again and it still works (see answer above). And yes, a nice result after 1.5 years! :)
Peter Vegter 26-Oct-19 14:59pm View
I have tried "Solution 1" again with several buttons and labels on the Form and also with different .NET Frameworks and this solution still works well with me.
Maybe you made a mistake somewhere else in your code?
Peter Vegter 23-Mar-18 15:39pm View
The 'FindAll' specification says: 'Retrieves all the elements that match the conditions defined by the specified predicate'.
A predicate is a delegate method that returns a bool value. The delegate is generic for the the passed argument (int, float, double, etc.) but the return value of a predicate method is always 'bool' - it's like short for 'bool MatchMethod<T>'. So, if you specify another return value, you get a compiler error just like when you do something like that with a 'normal' method:

void Test()
bool result = GetResult(); // error! - GetResult() does not return bool.

int GetResult()
return 10;
Peter Vegter 23-Mar-18 13:42pm View
You're welcome! Thanks for the answer and vote.
Peter Vegter 23-Mar-18 13:35pm View
Yes, you're right!
Peter Vegter 4-Mar-18 19:56pm View
Nice! But probably a little too complicated given the level of this question.
Peter Vegter 27-Feb-18 18:23pm View
You're welcome, and thanks for your reply and vote. Strange that the second code works well in my test application and not in your app. I'll have another look at it... - also thanks Richard.
Peter Vegter 27-Feb-18 14:19pm View
I've tested both my examples, and they both worked as expected: the file was released (with Dispose()) and deleted (with File.Delete()). Is this not working for you?
Peter Vegter 27-Feb-18 4:12am View
That's very nice, thank you!
Peter Vegter 26-Feb-18 15:57pm View
My mistake, I've updated my answer. That should work.
Peter Vegter 6-Feb-18 17:57pm View
You have to remove the 'static' keyword from your eventhandlers:

static private void PictureBoxes_MouseHover(object sender, EventArgs e)
private void PictureBoxes_MouseHover(object sender, EventArgs e)

same with the second one (MouseLeave)
Peter Vegter 3-Feb-18 20:45pm View
You should never dispose objects that you haven't created, but it does not always go wrong (immediately) as you've noticed.
In this case it goes wrong because of the use of the 'DoubleBuffer' (SetStyle) option set.
It tries to paint the control from the 'double buffer' using the graphics you have disposed.

Thanks for your answer and voting, Peter
Peter Vegter 19-Jan-18 19:24pm View
There are no differences between button or picturebox events (in this case). You can use (for example):

// set events
private void SetEvents()
pictureBox1.MouseEnter += PictureBoxes_MouseEnter;
pictureBox1.MouseLeave += PictureBoxes_MouseLeave;

pictureBox2.MouseEnter += PictureBoxes_MouseEnter;
pictureBox2.MouseLeave += PictureBoxes_MouseLeave;

// eventhandlers
private void PictureBoxes_MouseEnter(object sender, System.EventArgs e)
((PictureBox)sender).BorderStyle = BorderStyle.Fixed3D;

private void PictureBoxes_MouseLeave(object sender, System.EventArgs e)
((PictureBox)sender).BorderStyle = BorderStyle.FixedSingle;
Peter Vegter 6-Jan-18 14:17pm View
You're welcome and yes, you're right about the function limit. A function must end sometime... :)
A recursive function is usually not easy to follow and understand. Well done!
Thanks for your kind replies and votes!
Peter Vegter 24-Dec-17 15:21pm View
It is a typo, it must be "can not be so bad". I usually check what I have written but not good enough this time. Sorry about that!
Incidentally, I myself have no objection to static methods and use them whenever I deem it necessary.
Peter Vegter 23-Dec-17 6:08am View
You're welcome. I think I saw this construction somewhere as a suggestion from Microsoft, so it can be that bad. Thanks for the reply.
Peter Vegter 14-Dec-17 22:18pm View
In that case you could create a 2d cards[4][13] array that you fill with (do it in a loop):

String[][] table = new String[][] { { "Spade Ace", "Spade 2", ...}, { "Diamond Ace", "Diamond 2", ...}, { "Heart Ace", "Heart 2", ...}, { "Club Ace", "Club 2", ...}};

and select a card with:

LuckyCard = "Lucky Card is " + table[suitLucky][cardLucky];

But this just isn't the best way to do it...
Peter Vegter 28-Oct-17 12:26pm View
File.ReadAllLines(fileName).ToList(); requires .Net 4.

You have to use something like:

List<string> allQuestions = new List<string>();
string[] readLines = File.ReadAllLines(fileName);

or, you don't have to use a list at all:

string[] allQuestions = File.ReadAllLines(fileName);
string question = allQuestions[r.Next(allQuestions.Length - 1)];
Peter Vegter 10-Jul-17 17:22pm View
The scope (where it's 'visible' and can be used) of a variable is determined by the 'space' where it's declared. The assignment does not change the original scope of the variable.

In your example the variable i is 'visible' in the entire Main() method, including any containing ('inner') blocks, because it's declared in the most outer block:

public static void Main()
int i; // declaration
i = 1; // i is also 'visible' here
i = 2; // i is also 'visible' here
i = 3; // i is also 'visible' here
Console.WriteLine(i); // prints 3

The variable i is not 'visible' in outer blocks:

public static void Main()
// outer block starts here
int i; // declaration in inner block
i = 1; // i is also 'visible' here
i = 2; // i is also 'visible' here
i = 3; // i is also 'visible' here
Console.WriteLine(i); // i not 'visible' in outer block: error
Peter Vegter 10-Jul-17 5:24am View
You could do that except that the compiler 'thinks' i may be unassigned because the for loop may not run (we know better than the compiler).If you use: int i = 10; it's OK.

It's about declaration, assignment, scope and lifetime of variables...

Maybe have a look at these explanations for more clarity?:
Peter Vegter 8-Jul-17 17:31pm View
You forgot the () after CallDLL, making it a Property instead of a Method.
So make it a property by adding a Get and/or Set, or add the ()...
Peter Vegter 4-Jul-17 21:55pm View
Yes, you're right. Sorry about that. Thanks.
Peter Vegter 1-Jul-17 11:56am View
You're welcome. Good luck with your game!
Peter Vegter 1-Jul-17 10:35am View
What does 'aVt[x1,y1,s1]=true' mean? An array with 3 integers (or bools) doesn't have a 'true' property by itself.
If you explain what it is you want to do, perhaps I can help you some more...

PS. You can change 'PropertyName' to a name you like.
Peter Vegter 30-Jun-17 13:16pm View
You're welcome. Glad you liked it!
Peter Vegter 8-Jun-17 6:13am View
Thank you Karthik!
Peter Vegter 7-Jun-17 22:42pm View
You're welcome. Thanks for your kind reply.
Peter Vegter 14-Mar-17 16:21pm View
You're welcome. Thanks for the reply.
Nice 'problem', I needed this construction to start and stop a timer driven option...
Happy coding, Peter
Peter Vegter 6-Feb-17 14:27pm View
Very nice! Thanks for your reply.
Kind regards, Peter
Peter Vegter 28-Feb-16 6:07am View
For how to use a try/catch block you could start here:
It's not really difficult, good luck.
Peter Vegter 27-Feb-16 23:03pm View
I don't know why it 'puts spaces between entries' and 'duplicates entries': please compare your code to my example carefully, it should not do that.
When you add text to the textbox it scrolls down, you can't prevent that. You can scroll (back) to the first line with: txtName.SelectionStart = 0; txtName.ScrollToCaret();
Also if you don't want to add empty array items (strings), use: if (string.IsNullOrEmpty(item)).
For a bit faster and 'smoother' adding of the items to the textbox use txtName.SuspendLayout() and txtName.ResumeLayout().
Peter Vegter 8-Dec-15 4:37am View
+5 doing it the Linq way!
Peter Vegter 8-Dec-15 4:37am View