|
Christian Graus wrote: you win moron of the day.
for not using VB?
|
|
|
|
|
Luc Pattyn wrote: Christian Graus wrote:
you win moron of the day.
for not using VB? OMG
For not using his brain.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi.
To all Code Project members.
Vb.Net related question.
My question is that I have loaded an image in picturebox after that
i have completetly read to this image from pictureBox using getpixel
method. Now i have a big problem that As i am reading a pixel after reading I want to change color of that (point)pixel at pictureBox
coordinates not in image coordinates. So that I could see that i have
read to this pixel from image. and PictureBox is Showing with any
color that pixel has been readed.
Thanks to All.
|
|
|
|
|
You have two issues
1 - you're using a picture box when it's just a layer that gets in the way of what you want to do
2 - you need to convert between the pixel space and the size of the control, which is made harder because you're using a picturebox
Ditch the picture box, draw the image yourself and track the ratio between the image size and size on screen to calculate your mouse position.\
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Hi I am making a hangman game I am pretty much done with it but I want to add hints in case people are struggling to figure out the word they are working on. It there a very simple way to add these hints?
|
|
|
|
|
Yeah, you write code to do it. Which bit are you stuck on ? What sort of hints do you want to show ?
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
an example of my code is this
Sub LoadWordArray()
strWordListArray(0) = "ELEPHANT"
strWordListArray(1) = "CARRIAGE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(2) = "ENVELOPE"
strWordListArray(3) = "PRESIDENT"
strWordListArray(4) = "ELLIPTICAL"
I want to have when the word elephant is being guessed a box or something that gives a hint to the person guessing that is i a very large gray anamal. You know something like that, it will be different for every word but thats the idea
|
|
|
|
|
OK, so you need to store the hint to go with each word, so probably an array of a struct instead ( word and hint(s) ). Then you need to decide how and when to display them
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Can you give me an example? Like I said I am new at this so I am not really sure what you mean. Thank you
|
|
|
|
|
What Christian means is instead of using a string array that you now have to store your words, create a structure that contains both the word and a hint string, and make an array of that structure.
HTH
|
|
|
|
|
Well, I gave you all the keywords you should need. Do you not know how to create a class or a struct ?
class HangmanWord
{
public string word;
public string hint;
}
is fine.
Beyond that, your task is not specific enough to give any sort of hint. You need to decide when and how to show a hint.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
another best simple way is to do a array with 2 dimensions:
strArray(1,1)= "Elephant", ""A Large Big Grey Animal"
then you assign it to you output to display the Hint(which will be your second dimension)
|
|
|
|
|
The error I get is "Timespan can not be converted to a string".
I did a lot of reading and experimenting on this problem.
My weakness is not understanding the methodology of timespan and parse-ing.
--------------------------------
Public Class Form1
Dim NowIs As Date
Dim NowWas As Date = Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NowIs = Now
TextBox1.Text = NowIs - NowWas
NowWas = NowIs
End Sub
End Class
--------------------------------------
The idea is for the text box to indicate the amount of time passed, in minutes.
Hours could elapse between events.
Thanks in advance to all those who help.
Steve B.
modified on Thursday, April 23, 2009 5:00 PM
|
|
|
|
|
Your problem lies at this line:
Laser Steve wrote:
TextBox1.Text = NowIs - NowWas
When you subtract two Dates, you get a TimeSpan structure. TextBox1.Text is a String type. TimeSpan and String aren't directly equatable. If you want to get the TimeSpan in minutes, use this instead:
TextBox1.Text = (NowIs - NowWas).TotalMinutes
It's really messy (if something goes wrong creating the TimeSpan, you get an ugly error. It also looks ugly), but it works. If you want to learn more about date and time, look into these links:
TimeSpan documentation
DateTime documentation
Date and time format strings (used in parsing methods as well as formatting, so these are important)
|
|
|
|
|
Hi, I have example here on how to get the difference of date and time in C#.
Please follow these step:
Step: 1
Create a timer then set the interval to 10 and enabled to true.
Step: 2
Create 3 Label. Label1,Label2,Label3.
Step: 3
Create 2 Datepicker. Name it dtfrom and dtto.
Step: 4
Create a Button1
Then Copy this Code at your form:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{label1.Text = dtfrom.Value.ToString();}
private void timer1_Tick(object sender, EventArgs e)
{label2.Text = string.Format("{0:G}", DateTime.Now);}
private void button1_Click(object sender, EventArgs e)
{
TimeSpan ts = new TimeSpan();
DateTime dt1,dt2 = new DateTime();
dt1 = dtfrom.Value;
dt2 = Convert.ToDateTime(label2.Text);
ts=dt1.Subtract(dt2);
label3.Text = ts.ToString(); //Answer
}
for more information visit this: <a href="http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html">http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html</a>[<a href="http://codeincsharp.blogspot.com/2008/05/how-to-get-date-and-time-difference-in.html" target="_blank" title="New Window">^</a>]
|
|
|
|
|
Try This:
Public Class Form1
Dim NowWas As Date = Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = Now.Subtract(NowWas).TotalMinutes.ToString
End Sub
End Class
|
|
|
|
|
Try TextBox1.Text = Convert.ToString(NowIs-NowWas)
|
|
|
|
|
how can i go from the last item in a combobox to the first item.
With the folowing code i go always to the second item.
Private Sub ComboBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseWheel
Dim x As Integer
x = ComboBox1.SelectedIndex.ToString
If x = 95 AndAlso e.delta = -120 Then
ComboBox1.Text = ComboBox1.Items(0).ToString()
End If
End Sub
so i tried a lot of things but i gives me always the second item.
thanks.
|
|
|
|
|
If you want the first item in the combo box to be selected, can't you just use:
ComboBox1.SelectedIndex = 0
?
|
|
|
|
|
no even that gives the second item
|
|
|
|
|
Are you sure that:
A) this code block is being executed
B) there isn't any other code which sets the selected index of the combo box after this code block.
I'm guessing that the index is being set elsewhere because ComboBox1.SelectedIndex = 0 will select the first item.
|
|
|
|
|
Yes i am sure
i wrote
if combobox.selectedindex = 19 then
combobox.selectedindex = 0
end if
and this gives me the second item
i had tried that before thats why i asked it here.
i would say try it.
|
|
|
|
|
Ah, I have just tested and found that after the selected index of the combo box is set, the mouse wheel movement is actioned. That is, if you scroll downwards, then after setting the combobox to index 0, the scroll down is done (but if you scroll upwards then it is fine).
The only way I can think of around this (which isn't very pretty) is to add and event handler after setting the index of the combo box. Something like:
Private Sub ComboBox1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseWheel
If ComboBox1.selectedindex = 19 then
AddHandler ComboBox1.SelectedIndexChanged, AddressOf SetIndex
End If
End Sub
Private Sub SetIndex(ByVal sender As Object, ByVal e As System.EventArgs)
ComboBox1.SelectedIndex = 0
RemoveHandler ComboBox1.SelectedIndexChanged, AddressOf test
End Sub
Like I said, not a pretty solution so maybe someone else has other ideas?
modified on Wednesday, April 22, 2009 1:47 PM
|
|
|
|
|
your solution doesn't work because of the word "test".
Test is not decleared.
if i change it to setindex in run the project then the first item does not come it stays at the last item.
sorry couldn't response earlier
thanks
|
|
|
|
|
the only ting i can do is ad an emtpty string as last item
and then
If ComboBox1.SelectedIndex = 20 Then
ComboBox1.SelectedIndex = 0
20 is the last item as a empty string
that works but it's like you said even not so nice.
|
|
|
|