|
I totally don't understand your question, if one exists at all. Can you please rephrase your question so that a suitable answer can be thought of? Until then, liquid nitrogen.
|
|
|
|
|
Thanks,
That issue i solved it already.
But i have another thing that.
like DateTime Packer i want to show only Month & Year.
doese it has property for do that or not ?
How can resovle it ?
VB.Net
|
|
|
|
|
I would explore the relevant classes in the documentation at http://msdn.microsoft.com
|
|
|
|
|
Strange title... but i wan't to explain your what i mean.
I have a form, with one textbox. This textbox should be useable with commands such as examples:
/title TITLE OF FORM
so the form title is TITLE OF FORM (without /title infront) - I have tried with splits, serveral of string formats and much more but without any luck and i don't seem to find it on google with search tags: TextBox, Command, Strings etc.
I hope you can help me with this, if you don't have any idea what i am talking about, you can ask in this thread and i can try to explain.
I use Visual Studio 2008 VB Form
|
|
|
|
|
Should be relatively easy, just use a select case statement on the first word in a text box, and use a default case for unknown commands. I did something similar for a chatbot...
|
|
|
|
|
A strange title deserves a strange answer. I've divided this into three smaller tasks, each with code;
dim input as string = "/title HELLO"
This is where you get the command from the user. Next, you'd need to split this in the portion that represents the command (e.g. "/title"), and the portion that represent the arguments (e.g., "HELLO")
dim indexOfSpace as integer = input.IndexOf(" ")
dim command as string = input.SubString(1, indexOfSpace - " ".Length)
dim args as string = input.SubString(indexOfSpace)
Lastly, you'd need something to apply these new values.
Select Case command
Case "title": Text = args
Case "color": Color = Color.FromName(args)
End Select
Good luck
I are Troll
|
|
|
|
|
I'm trying to make a client to a text based game. I've asked the question before, but now I've got a little bit more to work with. What I need is some help with it. I'll show the code first.
Code for my 'tcpListener' which I've actually added to my overall project as a Console Application - Module1
Imports System.Net.Sockets
Imports System.Text
Module Module1
Sub Main()
Dim tcpListener As New TcpListener(6100)
Dim requestCount As Integer
Dim clientSocket As TcpClient
tcpListener.Start()
msg("Server Started")
clientSocket = tcpListener.AcceptTcpClient()
msg("Accept connection from client")
requestCount = 0
While (True)
Try
requestCount = requestCount + 1
Dim networkStream As NetworkStream = _
clientSocket.GetStream()
Dim bytesFrom(10024) As Byte
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
Dim dataFromClient As String = _
System.Text.Encoding.ASCII.GetString(bytesFrom)
dataFromClient = _
dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
msg("Data from client - " + dataFromClient)
Dim serverResponse As String = _
"Server response " + Convert.ToString(requestCount)
Dim sendBytes As [Byte]() = _
Encoding.ASCII.GetBytes(serverResponse)
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Flush()
msg(serverResponse)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End While
clientSocket.Close()
tcpListener.Stop()
msg("exit")
Console.ReadLine()
End Sub
Sub msg(ByVal mesg As String)
mesg.Trim()
Console.WriteLine(" >> " + mesg)
End Sub
End Module
And this is my code for the actual client
Imports System.Net.Sockets
Imports System.Text
Public Class lokMudClient
Dim clientSocket As New System.Net.Sockets.TcpClient()
Dim serverStream As NetworkStream
Private Sub btnConnect_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnConnect.Click
Dim serverStream As NetworkStream = clientSocket.GetStream()
Dim buffSize As Integer
Dim outStream As Byte() = _
System.Text.Encoding.ASCII.GetBytes("Message from Client$")
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Dim inStream(10024) As Byte
buffSize = clientSocket.ReceiveBufferSize
serverStream.Read(inStream, 0, buffSize)
Dim returndata As String = _
System.Text.Encoding.ASCII.GetString(inStream)
msg("Data from Server : " + returndata)
End Sub
Private Sub lokMudClient_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
msg("Client Started")
clientSocket.Connect("204.209.44.6", 6100)
outputBox.Text = "Client Socket Program - Server Connected ..."
End Sub
Sub msg(ByVal mesg As String)
outputBox.Text = outputBox.Text + Environment.NewLine + " >> " + mesg
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOptions.Click
dialogsForm.Show()
End Sub
End Class
Now, for some reason, I can't see any output in my 'outputBox' which I've set inside a panel labelled 'outputHolder.' So, I'm a little lost as to which direction I need to be going with this. I thought I had it down, but I guess I don't....
P.S. I'm not getting any errors, but I am getting a warning which reads:
"'Public Sub New(port As Integer)' is obsolete. 'This method has been depracated. Please use TcpListener(IPAddress localaddr, int port).'
And it can be found on line 5, column 13 of the tcpListener project. Could this be the reason I'm not finding any text in the rich text box I'm trying to use to hold the output of the server? Suggestions, fixes, please provide and thank you in advance.
|
|
|
|
|
Hello,
I am new to this forum, and a begginer programer.
I am looking for some advice on how to use a button control to open the openfiledialog which displays a picture on a form.
Here is the code i currently have, it works except for the fact that the openfile dialog just repeatedly comes up even after i choose the file to open. I only want the file to open when i hit button2.
Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim button2 As Boolean = False
If button2 = True Then
If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Form1.openDiag.FileName
End If
End If
' Create image.
Dim Newimage As Image = Image.FromFile(user)
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
e.Graphics.DrawImage(Newimage, ulCorner)
End Sub
modified on Friday, December 11, 2009 3:59 AM
|
|
|
|
|
The MyBase.Paint event happens a lot, that's why your dialog gets openend constantly.
Setting aside the question of how wise it is to try and do this kind of operation in that particular event, you are checking to see if the boolean button2 is false, which would be the correct way to prevent this code from being executed all the time. However, because you dim the boolean inside the same event with an explicit value of False, it will never ever be true.
If this really does what you say it does, than the code you posted is not the code that you are running, or you just didn't post the entire code here. If the boolean somehow gets set to True between its creation and checking it's value, the Paint event may fire again before the boolean gets set to false (which, according to this code, only happens at the moment you create the boolean). Which is the main reason not to use this event for what you are doing here.
So the questions are:
- did you create a boolean with the exact same name outside this event, particularly at the class level (outside any sub or function) ?
- Is there any code anywhere in your application that should set that boolean to True?
Tips:
- Use the Try catch clase and run your app in visual studio, and step through it line by line (put a break point at the first line, and press F11 to advance one statement).
- Try to run your code inside a controlled event, like the button click event, first, before using it in volatile events like Paint.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hello Johan,
Thanks for the reply!
Maybe i worded my problem wrong...im pretty new at this so it is slightly hard for me to accurately describe what is wrong.
What happens is:
I go to the correct form, and automatically, without me clicking on button2, the openfiledialog pops up and allows me to choose an image which then gets displayed on the form. Then the dialog pops up again and wants a new file etc etc in a continuous loop, somehow just completely bypassing my button. I have since tried some new code, this however does the exact same thing. I will post my entire code for that form now, maybe that will help you understand it more.
Thanks again!
Imports System.IO
Imports System.Windows.Forms.MouseEventArgs
Imports System.Windows.Forms.Form
Imports System.Windows.Forms.PaintEventArgs
Public Class Edtor
Private gfx As Graphics
Public user As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Visible = True
Me.Visible = False
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
End Sub
Private Sub Edtor_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
gfx.Dispose()
End Sub
Private Sub Edtor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gfx = Me.CreateGraphics()
End Sub
Public Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
If (Me.SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Me.SaveFileDialog1.FileName
End If
End Sub
Public Sub Edtor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If RadioButton1.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Red, rect)
End With
End If
If RadioButton2.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Blue, rect)
End With
End If
If RadioButton3.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Black, rect)
End With
End If
End Sub
Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Call Button2_Click(sender, e)
' Create image.
Dim Newimage As Image = Image.FromFile(user)
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
e.Graphics.DrawImage(Newimage, ulCorner)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpic.Click
If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Form1.openDiag.FileName
End If
End Sub
End Class
The bolded is where the problem is. I dont want the openfiledialog to appear UNTIL i click button2.
|
|
|
|
|
First please use the 'code block' or 'inline code' for posting code. Makes it easier to read the code.
As to your problem, you don't need the paint event. Using this event is why you have the endless loop.
Paint event is triggered every time the form repaints (logic isn't it ) and since you call a dialog in your paint event every time that dialog closes your form is repainted so your dialog is opened again and so on...
Suggestion:
Remove your paint event completely.
Draw your image in your button click event and go from there (might I suggest a picture box to display your image.)
|
|
|
|
|
Oh sorry, i will post in code block next time.
The reason i cant do that, is because im using this application as a sort of paint...and once i loaded the photo into a picture and started painting on the form, i couldnt paint over top of the picturebox...but if i load the picture directly onto the form, i am able to pain over it, and thats where my problem is.
If there is a way to paint on top of a picturebox, i would have done that, but i couldn't see a way to do that. I can load a picture onto the form and paint on it just fine if i explicitly tell it where the file loacation is, but using the openfiledialog into the mix seems to really mess it up and I just can't figure out how to fix it..
Thanks for your help!
|
|
|
|
|
Ah so your not only painting the image in that case your right you can't use the picture box.
you might want to check out Christian Graus his articles here[^]
I think it was him who had a couple on this sort of thing.
As to your immediate problem I would do the following:
In your button click (and only there) open your file dialog, and save the selected image into a global variable for that form.
In the paint event draw that image and do nothing more than that, so don't open the file dialog in there.
Pseudo code:
private img as image
private sub button_click ...
if openfiledialog.showdialog = ok then
img = image.fromfile(openfiledialog.getpath)
end if
end sub
private sub paint_event....
'draw the img object
end sub
|
|
|
|
|
I figured it out with the help of several different forums thanks alot guys! Heres the code i ended up with in case your curious.
Imports System.IO
Imports System.Windows.Forms.MouseEventArgs
Imports System.Windows.Forms.Form
Imports System.Windows.Forms.PaintEventArgs
Public Class Edtor
Private gfx As Graphics
Public user As String
Private pathset As Boolean
Dim button2 As Global.System.Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Visible = True
Me.Visible = False
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
End Sub
Private Sub Edtor_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
gfx.Dispose()
End Sub
Private Sub Edtor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gfx = Me.CreateGraphics()
End Sub
Public Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
If (Me.SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Me.SaveFileDialog1.FileName
End If
End Sub
Public Sub Edtor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If RadioButton1.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Red, rect)
End With
End If
If RadioButton2.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Blue, rect)
End With
End If
If RadioButton3.Checked = True Then
If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
Dim rect As Rectangle
With rect
.X = e.X - 1
.Y = e.Y - 1
.Height = 2
.Width = .Height / .Height
gfx.DrawRectangle(System.Drawing.Pens.Black, rect)
End With
End If
End Sub
Private Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If pathset = True Then
If button2 = True Then
If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Form1.openDiag.FileName
End If
End If
' Create image.
Dim Newimage As Image = Image.FromFile(user)
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
e.Graphics.DrawImage(Newimage, ulCorner)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpic.Click
If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Form1.openDiag.FileName
pathset = True
End If
End Sub
End Class
|
|
|
|
|
treashunter wrote: I figured it out
Nice thread to read. 5ved.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Still not quite right I'm afraid, though good work.
You still have the dialog popping up in the Paint event, and that is a no-no.
All you need is to handle the Shown event, or override the OnShown method. In that method invoke Me.Button2.PerformClick() . The Paint event then just checks if the path has been set yet.
|
|
|
|
|
treashunter wrote: i will post in code block next time
Yes, please do. It makes it easier to read. Since you are new, I'll be a nice guy about it
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
treashunter wrote: Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Call Button2_Click(sender, e)
Okay, this is the main problem. The paint event (especially of the form) can happen many times per second even, and is an uncontrolled (by you) event. That means it will happen whether you want to or not.
So in your code, as is, the code in your button click event will be executed just as many times (whether you want to or not).
In other words, do not use the Paint event, but rather the Form's Load event, or if absolutely necessary, VisibleChanged , in which case you need to check whether the form is being hidden or made visible.
And a good opportunity to practice good coding techniques:
As a rule of thumb, do not call an event from within other events just to run the code inside that event. Rather create a separate sub and move the code in the event to it. So in your case:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpic.Click
OpenPictureDialog()
End Sub
Public Sub drawonform(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
OpenPictureDialog()
End Sub
Private Sub OpenPictureDialog()
Try
If (Form1.openDiag.ShowDialog() = Windows.Forms.DialogResult.OK) Then
user = Form1.openDiag.FileName
End If
Catch ex as Exception
MsgBox(ex.ToString)
End Try
End Sub
My advice is free, and you may get what you paid for.
|
|
|
|
|
As others have mentioned, do not have this type of operation inside a procedure that handles the Paint event as Paint event does happen often and you cannot control when it is triggered or not. From what I read of your description of what you are trying to achieve, you should be putting the code to open your open dialog in a button click event procedure for the button in question.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
In vb6.0, how can i check Internet connection. that is. Is net connected or not.
Send source code please
|
|
|
|
|
Tufail Ahmad wrote: Send source code please
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef dwflags As Long, ByVal dwReserved As Long) As Long
Public Function IsOnline() As Boolean
Dim LFlags As Long
IsOnline = InternetGetConnectedState(LFlags, 0&)
End Function
I are Troll
|
|
|
|
|
IsOnline = InternetGetConnectedState(LFlags, 0&)
In the above line, LFlags returns some values, what does it mean.
Note: I am connected to Internet through LAN
|
|
|
|
|
|
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Function Check_Internet_Connection() As Boolean
If InternetCheckConnection("http://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
Check_Internet_Connection = False
Else
Check_Internet_Connection = True
End If
End Function
Best Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
Tufail Ahmad wrote: Send source code please
Sorry, it is not how this site works. People will offer help and hints as to what to do, but to just throw out code, no.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|