New Posts  All Forums:Forum Nav:

C# small app help!

post #1 of 9
Thread Starter 
Hey everyone,
I'm making a small application, using C#.
Anyways, its a Web Browser.
Now I have 2 Questions to ask.

1: In the address bar, if the user doesn't type http:// the application gets an unhandled error, then closes.
How can I make it automatically enter http:// if the user hasn't entered it.

2: Shortcut keys; how do I assign ENTER as a shortcut to the link.
EG: you type http://www.google.com. Then tap enter and it goes to the page, instead of having to click GO.

All helpers get a +REP.
Thanks,
Ben
post #2 of 9
Being more VB.Net instead of C# you'll have to improvise however..

1.
Just check the string and if it doesn't have the proper predicate, append it.

In example VB.Net and I'm not at my development box but

Code:
  If Not txtAddress.Text.Upper.StartsWith("HTTP://") Then txtAddress.Text = "http://" & txtAddress.Text
I tend, since I work with a lot of code and a lot of OTHER PEOPLES code try to force a case so I can evaluate easier. It may not be quicker but if someone put in HtTp:// or HTtp:// or any other variation your Upper will force to do the eval against your known Upper value and complete true/false without incident

2.
The address box your using, say txtAddress, has an event called KeyDown and/or KeyPress. Just check, on that event handler, if the keypress = CHR(13) which if I remember correctly is the ENTER/RETURN key. If said keypress key is equal then just fire off the event for the GO button click.

I'm remoting to my development now so I'll have exact code in 5-10
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #3 of 9
Thread Starter 
Cheers mate, I can't input the code right now. As im not on my pc.
I gave ya REP+
post #4 of 9
OK.. This is in VB.Net 2003

Form Objects:
TextBox = txtAddress
Button = btnGO

To pre-check for existence of string predicate on btnGO.Click() Eventhandler

Code:
    Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
        If Not txtAddress.Text.ToString.ToUpper = "HTTP://" Then txtAddress.Text = "http://" & txtAddress.Text.ToString
    End Sub
Trying to get the last one.. not sure how to do it best.. Events, Delegates.. Hmmm

LOL learn something new everyday Here's the BEST way to do the ENTER/RETURN press

Code:
    Private Sub txtAddress_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAddress.KeyPress
        If e.KeyChar = Chr(13) Then Call btnGO.PerformClick()
    End Sub
It simply checks if the Keypress is CHR(13) and if so then calls the button's click event.. Much easier than I've done in the past, hehe
Edited by Ictinike - 12/17/08 at 10:17pm
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #5 of 9
Thread Starter 
Code:
 {
     if (!txtAddress.Text.Upper.StartsWith("HTTP://")) txtAddress.Text = "http://" +    txtAddress.Text;
 }
Would that be right in C#?
post #6 of 9
Quote:
Originally Posted by sktfreak View Post
Code:
 {
     if (!txtAddress.Text.Upper.StartsWith("HTTP://")) txtAddress.Text = "http://" +    txtAddress.Text;
 }
Would that be right in C#?
Yep I believe so.. If the same syntax on the .Text.Upper.StartsWith

Those you might have to find out what the equivalent C# syntax is compared to my VB.Net..

Between my morning meetings tomorrow I'll try to do this in C# and get specifics but I think your well on the way. The BIGGEST thing is the logic behind what you want to do.

Coding is 1/2 logic and 1/2 art IMHO.

You can things multiple ways but it's how you combine everything into the final app that is like a painting

2am now, still no sleep but I'm going to try again.. Insomnia sucks
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #7 of 9
Thread Starter 
Quote:
Originally Posted by Ictinike View Post
Yep I believe so.. If the same syntax on the .Text.Upper.StartsWith

Those you might have to find out what the equivalent C# syntax is compared to my VB.Net..

Between my morning meetings tomorrow I'll try to do this in C# and get specifics but I think your well on the way. The BIGGEST thing is the logic behind what you want to do.

Coding is 1/2 logic and 1/2 art IMHO.

You can things multiple ways but it's how you combine everything into the final app that is like a painting

2am now, still no sleep but I'm going to try again.. Insomnia sucks
Cheers mate, just pm me with the finished piece
Ben
post #8 of 9
Quote:
Originally Posted by sktfreak View Post
Code:
 {
     if (!txtAddress.Text.Upper.StartsWith("HTTP://")) txtAddress.Text = "http://" +    txtAddress.Text;
 }
Would that be right in C#?
I don't see why you would need the .Upper in there. You should be able to do it without.
post #9 of 9
Quote:
Originally Posted by BiG O View Post
I don't see why you would need the .Upper in there. You should be able to do it without.
I don't disagree, to an extent.

However, what if the user types HTtp:// or htTP://? The evaluation against would fail -or- he would have to provide a check for each possible variation of the caps and no caps.

If he just ~forces~ the users input UPPER then he can easily and only once evaluate the values of the string instead of the case sensitive values.

Just a code thing I do developing over 16 years

In example :

His app wants to detect if the http:// predicate is there typed by user so he doesn't have to add it. If he added it each time he could possibly get http://http:// and so on.

So...

User types "www.google.com"
Code checks the string to see if it starts with (case sensetive) "http://"
Code see's no predicate and adds it.. result = http://www.google.com

User types "HttP://www.google.com"
Code checks the string to see and evaluates against literal "http://"
Since HttP:// is NOT http:// then result = http://HttP://www.google.com

User types "htTP://www.google.com"
Code checks string again and evaluations against literal "http://"
Since htTP:// is NOT http: then result = http://htTP://www.google.com

and so on..

Using this method forces out the case sensitive so he's always evaluating an Upper value of what the user typed in against a known Upper evaluator.

user types "HtTp://www.google.com"
Code UPPERS input and evaluates against literal "HTTP://"
Since Upper(HtTp://) = HTTP and IS EQUAL to HTTP:// result = http://www.google.com

~fin


Can be done without but not in one line like that..
Edited by Ictinike - 12/18/08 at 3:05pm
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming