|
No wonder I couldn't break it!
|
|
|
|
|
Hi,
i want to determine path of system Windows folder.There r option for determine the path of Program files,my document,etc folder but no option for windows folder.
require some clue or hint. any help will be appreciated.
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Rupesh Kumar Swami wrote: There r option for determine the path of Program files,my document,etc folder but no option for windows folder
Wanna bet?
Imports System.Io
.
.
.
' This will get the parent directory of the path returned by SpecialFolder.System
' which is normally C:\Windows\System32. The parent folder would be C:\Windows
Dim systemPath As String = Path.GetDirectoryName( _
Environment.GetFolderPath(Environment.SpecialFolder.System))
|
|
|
|
|
Thanks . one more question
i create some label with font type "Kristen ITC.TTF". i want to copy this font to Client system at run time if font is missing.
Following are the code
Dim str As String<br />
Try<br />
Dim systemPath As String = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.System))<br />
str = systemPath & "\fonts"<br />
systemPath = systemPath & "\Fonts\ITCKRIST.TTF"<br />
If File.Exists(systemPath) Then<br />
<br />
Else<br />
File.Copy(Application.StartupPath & "\ITCKRIST.TTF", str & "\ITCKRIST.TTF", True)<br />
End If<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try
however this code copy the specified font to client system but there r no effect on my app.
Label are generated with Microsoft scan serief font.
i have no idea where i m wrong?
any idea or clue ?
thanks in advance
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|
Rupesh Kumar Swami wrote: however this code copy the specified font to client system but there r no effect on my app.
The font MUST be installed at the time your app is install on the system. You cannot do it from your code and expect it to work. Just copying the font to the Fonts folder will not install the font. Also, the font will not be available to your code during that session of your app. You app will have to restart to get access to the font.
Install the font at application install time, not run-time. If the user running your app is a member of the Users group, and not the Administrators or Power Users groups, they won't be able to copy the font into the Fonts folder anyway.
|
|
|
|
|
uninstall the font on your machine. Then get your program to copy it into the font directory. Theoretically, the windows font installer should popup and install the font as it normally does with manual copy and paste. If it doesn't however you will have to find a way around it.
Posted by The ANZAC
|
|
|
|
|
Hi there,
I'm trying to execute a SQL command that works perfect with an Access DB, but it gives me an 'Incorrect syntax near the keyword 'COLUMN'' error if I use it on a SQL Server Database. Why is that?
Here is my code:
ALTER TABLE Staff ADD COLUMN [MaxDisc] single
SQL Server does not support 'single' as a data type and I’ve changed it to the following:
ALTER TABLE Staff ADD COLUMN [MaxDisc] real
Any help would be appreciated.
Regards, Werries
-- modified at 10:03 Tuesday 15th May, 2007
A programmer's life is good... or is it?? Ek dink nie so nie!
|
|
|
|
|
Easy. You've already found out that TSQL and Access's version of it are not the same. Access only supports a subset of TSQL and adds it's own "flavor" to some of what would be considered normal for other implementations of SQL.
If you wanted to support different database engines, you'd have to implement different data layers in your application to support them.
For instance, SQL Server supports batch queries, where Access does not. You'd have to implement the missing functionality in your own code instead of relying on the database engine to do it for you.
|
|
|
|
|
ALTER TABLE dbo.Staff ADD MaxDisk real NULL
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so
|
|
|
|
|
I have looked for this and the only answers I've found are for what I'm already doing.
I've tried all of the following and non of them work when I click in the textbox with the mouse.
uxBox1.SelectionStart = 0
uxBox1.SelectionLength = uxBox1.Text.Length
uxBox1.SelectAll()
uxBox1.Focus()
uxBox1.Select(0, uxBox1.Text.Length) Is there a missing step here? According to the properties of the textbox, it has selected text after this but it isn't highlighted. I used to be able to do this in .NET 1.1 but this is .NET 2.0.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
The events fire in a slightly different order in .NET 2.0. In addition, when, or even if, you call the Base classes Onevent methods can alter the results of your code.
What are you trying to do with this??
|
|
|
|
|
Dave Kreskowiak wrote: What are you trying to do with this??
I am just trying to highlight all of the text in the textbox so that when the user clicks on it or enters the box in anyway that it will be highlighted (selected).
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
I've come across this question before. I can't remember if it was here or some place else. The problem is the click causes the textbox to place the cursor and clear the selection. This undoes the select all you are attempting to do on the click event. I don't recall discovering a slick way around it but I did figure out a solution.
What I did was called a procedure asyncronosly. The procedure called thread.sleep for just a few milliseconds, which in practice wasn't necessary, but I figured better play it safe. After that it called selectall. Because the procedure is called asyncronosly it fires after the textbox has done it's normal thing of placing the cursor. Thus the highlighting happens after that event and "sticks".
I'm sure you could actually do this with a timer as well. Just set the timer to fire after 10 ms or so and when it does call selectall. This should create the same delay.
|
|
|
|
|
You didn't have to go through all this at all.
If you override the OnClick method, all you had to do was this:
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
' Call the base TextBox class' OnClick method so it does it's work.
' This also fires the Click event for our control so the form can
' handle the event if it wants to.
MyBase.OnClick(e)
' Then do what we really want it to do, AFTER the base TextBox does
' what it needs to.
MyBase.SelectAll()
End Sub
|
|
|
|
|
Where are you performing the override, in other words how do you tell it that it is the Textboxes event and not some other controls event?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
I believe the assumption was you were creating your own custom textbox. You can only override the event if you create your own class that inherits from textbox. Correct me if I'm wrong but you want to select all when the textbox recieves focus, right? If your selecting all on a normal click it should work just fine.
|
|
|
|
|
You create your own custom TextBox class, inheriting from TextBox. I do this all the time to get all kinds of functionality I want out of the stock controls. It amazes me that people will readily do this for other classes, but rarely do it using controls.
Public Class NumericTextBox
Inherits TextBox
Protect Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
' For some reason Keys.Back doesn't work for backspace, even though it's constant is 8!
If Char.IsNumeric(e.KeyChar) OrElse e.KeyChar.Equals(Keys.Delete) _
OrElse e.KeyChar.Equals(Convert.ToChar(8)) Then
' It's a key we'll allow, so let the base TextBox handle it normally.
MyBase.OnKeyPress(e)
Else
' Drop the key by not passing it to the base class. Pass Handled back up the chain.
e.Handled = True
End If
End Sub
' GotFocus is for when the user tabs into the TextBox
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
' Let the base TextBox do it's thing first.
MyBase.OnGotFocus(e)
' Then we'll select all the text.
MyBase.SelectAll()
End Sub
' If the user clicks anywhere in the TextBox, select all the text in it.
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
MyBase.SelectAll()
End Sub
End Class
You don't have to create a new project to do this, but I highly recommend doing it. This way, the control is reusable in any project with a simple reference to this project.
|
|
|
|
|
Actually you don't need to override the click event to get select all to work. The click event fires late enough that select all will work just fine when added to that event. I mis-spoke in my post. The problem wasn't selecting all when the user clicks a textbox. The problem was selecting all when the textbox gets focus ie. The Internet explorer address bar. I believe this is what the OP wants. Currently if the textbox got focus by the user clicking on it the highlighting would be undone by the click. Tabbing worked just fine however.
The focus event unfortunatly fires to early causing the select all to be undone (again only when clicked). Delaying the select all was the easiest solution as far as I could tell.
You could also respond to the click event which fires late enough but clearly we don't want to select all on every click. So you need a global boolean to see if the textbox just recieved focus, which would be the only time you'd want to select all. Unfortunatly because we are handling this in the click event we aren't handling the focus recieved by tabbing. Thus additional code would be required in the focus event also. The delayed approach to me seemed the most straight forward and cleanest. Plus it had the added benefit of easily being able to handle one or multiple textboxes even if a custom textbox wasn't going to be created. If I missed the obvious please let me know. But the delayed method just seemed cleanest in my opinion and was just as trivial to pull off.
-- modified at 12:00 Tuesday 15th May, 2007
|
|
|
|
|
TwoFaced wrote: Actually you don't need to override the click event to get select all to work. The click event fires late enough that select all will work just fine when added to that event.
Yeah, but I believe in encapsulating the functionality I want into the control and not cluttering up my form code to get a control to do what I want.
TwoFaced wrote: The focus event unfortunatly fires to early causing the select all to be undone (again only when clicked). Delaying the select all was the easiest solution as far as I could tell.
This is also a reason to create your own control. You get greater flexibility over what you need to do when to get your functionality to work properly.
|
|
|
|
|
Good points. I guess I just assumed the OP wasn't creating a custom control. Perhaps he is or should.
However the problem still persists. The OP wants to select all when the control gets focus. So the question is what's the cleanest easist way to accomplish this? Using BeginInvoke to call a procedure asncronosly will definitly work as that's how I pulled it off before. However I realize now it can probably be done with less code if the click event was handled instead. We'd still need to select all when the user tabs so that code would need to additionally appear in the GotFocus event. Either solution would work and are the only two I can see.
|
|
|
|
|
I just showed him the basic technique in that code sample. It's up to him to implement the functionality he wants in the events he wants.
|
|
|
|
|
I need this in a Windows app not a Web app. Sorry for the confusion.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
TwoFaced wrote: But the delayed method just seemed cleanest in my opinion and was just as trivial to pull off.
It's just plain bad practice to put a thread to sleep so a UI elemnt can update. I don't believe in putting in Thread Sleeps anywhere for any reason other than to wait a certain amount of time to repeat a task.
Also, your method leave your control open to failure. If the system gets very busy, your thread sleeps then wakes up, but the process you're waiting on hasn't had a chance to execute. Even if it happens just once out of a thousand times, that's one too many, and it'd be a bitch to debug.
Your method doesn't take into account future changes to the base controls either. Mine, on the hand, doesn't care what the base control does. It patiently waits for the base control to do whatever it wants, for however long it wants, then updates to the control to get the functionality we need, only when the MyBase.Onwhatever call returns.
Oh! And there is also a limit to the number of Timers supported per-process and system-wide.
-- modified at 12:27 Tuesday 15th May, 2007
|
|
|
|
|
I didn't say put the UI thread to sleep. I suggested calling a procedure asyncronosly. This procedure would work on a seperate thread. To be clear this is what I had in mind.
1) The focus event fires
2) In that event we call another procedure asyncronosly
-This allows the normal cursor placement to finish
3) The procedure we called fires and highlights everything in the textbox
Putting the [i]secondary[/i] thread to sleep for a split second was just a precaution to make sure the select all fired late enough. I know your far more knowledable then I and I may be missing the problems this method creates. Even if they would be rare. But thats how I did it and the method seemed to work. I suggested a timer as a secondary option to pull off the delay. In this case putting the thread to sleep obviosly wouldn't be needed and certainly not desired. It was just an alternative thought, not really what I was suggesting.
As you've already made clear it probably is best to create a custom control.
|
|
|
|
|
TwoFaced wrote: I didn't say put the UI thread to sleep. I suggested calling a procedure asyncronosly. This procedure would work on a seperate thread.
This would work, PROVIDED the thread that your thread was waiting for completed its work in the time alloted. If the system is under load, it's entirely possible this won't happen.
TwoFaced wrote: -This allows the normal cursor placement to finish
It assumes that the process completes. It has no way of knowing it.
|
|
|
|