
mhsueh001
Avatar/Signature-
Posts
41 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by mhsueh001
-
How to capture Keypress event in a custom control?
mhsueh001 replied to mhsueh001's topic in Windows Forms
While I agree it maybe overkill, I believe it maybe the only way to go so I can encapsulate everything into my control, without forcing another coder to code the requirements into their code. It also modularizes it. I've got it working and found my solution here: http://www.developer.com/net/net/print.php/11087_2193301_1 -
How to capture Keypress event in a custom control?
mhsueh001 replied to mhsueh001's topic in Windows Forms
Ok, this is basically the direction I started heading. How do I go about this? -
How to capture Keypress event in a custom control?
mhsueh001 replied to mhsueh001's topic in Windows Forms
Hi Iceplug, I'm not asking to hog all of the keystrokes. Here is my problem. Our company has tried to achieve a paperless office. And for a company that does data entry, this is no easy task. Teams are developing individual control modules. Mine is a composite control that is to display a scanned image. A document that must then be read by a data entry person, interpreted, and data then needs to be entered in other people's controls. There are multiple controls on a single form. The problem is that my control, which displays the image must allow a data entry person to scroll through the page. They need to be able to adjust the image size so they can read the document and move through the image. They do not like the mouse. Data entry people prefer all keyboard strokes because it's faster for them. So to toggle through the page, I've written some methods in my control to move up and down, left and right through the page. However I need to be able to move through the page WITHOUT requiring my control from having the focus. My control only displays the image. Other controls are responsible for handling the data entry. I would prefer not to do it at the form level because my "document viewer" is used on several data entry forms and to have to code the same repetitive keydown event for each form doesn't make sense, not to mention the fact that that's tasked to another person, and it creates a distinct problem of not being object oriented. My control, must capture all keystrokes, and determine if it's a keystroke to move the image up, down, left, right. (Basically hoping to assign these to function keys or keyboard combinations.). Anyways, that's my problem, which is why my control needs to receive all the keystrokes and determine if it's one of the key's pressed. Unless you know of a better way to trap an exact key such as F4 being pressed. Any solution? -
Hi RudeYute If this is the case, then my first piece of code should do the trick. It goes through each item in the list box and performs the action it finds. It doesn't matter what what is in the list box. The code I wrote basically starts from the top of the list box and moves down through the list. Each time it goes through and finds the action that it must perform through the if...then statement. What you must do is code an action that is added to the list. If your list has Up, down, left, right. Then you must have a corresponding if...then for each of the actions. If you don't have an if...then statement for that action, that action will be ignored. Basically my first code listing does this. 1. Step through each item in the listbox. (do while ...) 2. Analyze the action that we are asked to perform (if...then) 3. Perform that action (the block within the if then ... end if) 4. Retrieve the next item on the list and go back up to 1.
-
Hi RudeYute, First off, either your explaination is not correct or your code is not correct because the logic of the two don't match up. So I will do a best guess at explaining what I think you want, and you can correct me if I'm wrong. 1. I believe you're saying you've got a list box with a list of items in it. (I'm assuming these's aren't buttons as you've indicated) 2. You want an external button, when pressed, to analyze each of the items in the list box and perform an action if that item exists in the listbox. (this is for all items, and not just the selected one in the list box???) What you need to do is go through the list of all the items. Dim intDummyCounter as integer intDummyCounter = 0 'As long as there are items in the list box perform an action Do while intDummyCounter < Me.ListBox1.Items.Count If me.ListBox1.Items(intDummyCounter) = "Up" Then 'Perform the action for the "Up" ElseIf me.ListBox1.Items(intDummyCounter) = "Down" Then 'Perform the action for the "Down" '... etcetra End If 'Increment to the next item in the listbox intDummyCounter = intDummyCounter + 1 'Or simply intDummyCounter += 1 Loop If you only want the selected items you can loop through the SelectedItems list instead of the full list. (I placed ???? in my statement above because I believe this is what you really want) ie. Do while intDummyCounter < Me.ListBox1.SelectedItems.Count 'Do the check on the selected Items If me.ListBox1.SelectedItems.Items(intDummyCounter) = "Up" Then '... etcetra End If Loop
-
How to capture Keypress event in a custom control?
mhsueh001 replied to mhsueh001's topic in Windows Forms
-
How to capture Keypress event in a custom control?
mhsueh001 replied to mhsueh001's topic in Windows Forms
So basically you're saying I need to do an Addhandler and add the keydown event to every control on my custom control? This appears to work when the control is in focus, but I need to catch this event even when the control is not in focus. Any other ideas? -
Actually what you wrote is exactly what data binding is. Data binding binds information from a datatable (or the 0th datatable of a dataset) to a control. I believe what you're missing is the understanding that what you are binding to the text box is not the database table, but to disconnected copy of information in that table. Any changes you make to the data table aren't applied to your database table until you execute a command to perform those changes. There are a variety of ways to do this. Using the least amount of thought, Microsoft developed an SQLCommandBuilder, I believe oledb has a counter part as well. It writes the sql command for updating your table with the changes that were made to the data table. Check out Microsoft's own explaination: http://support.microsoft.com/kb/308055/EN-US/
-
I'm trying to create my own form control. Went through all the File->New->Project, selected Windows Control Library. I want to capture if a function key is depressed and I tried both the KeyDown event and the Key Press event. Private Sub UserControl1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 'My Code here End Sub Private Sub UserControl1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress 'My Code here End Sub However when run the control in a form, neither event is being captured. What am I doing wrong? I've tried putting break points at the top of the two delegates above, but the code never enters and runs. Help!
-
An update for this post. Thanks Hamburger1984, this works great. Just to add an additional note, for multiple image files, the routine has a memory leak. The fix should be before you try to load up the new image, make sure you dispose of the previous one. If Not Panel1.BackgroundImage is nothing then Panel1.BackgroundImage.Dispose() End If
-
Nope, that didn't work I'm already using the Onclick event to execute the vbscript routine. Also I'm using a HTMLbutton because the script I'm trying to run is for an activex control. thanks though.
-
Is there a way to run both a vbscript sub and a codebehind method with only one button click? I've got a button that needs to runs some client side code, then run some server side code. Any help would be appreciated.
-
Is there any way to get the values of a variable from the vbscript to a method in the codebehind? I have an activex control that runs client side. The activex control runs a number of times, and execution is controlled by a vbscript. I've got a counter in the script that counts number of times it was executed. Now I need to get that value into a routine in my codebehind after the user hits a submit button. Is this possible? (I would think it should be) Anyone know how to do this? Thanks.
-
I found this on the web: Add the following line to your page's Load event, replacing "btnSearch" with the name of your button. It uses a hidden Page method called RegisterHiddenField. Page.RegisterHiddenField("__EVENTTARGET", "btnSearch") Note: Intellisense doesn't show this event/method so when you type Page.RegisterHiddenField (RegisterHiddenField doesn't show up in the list. However after you hit the parenthesis it does shows the parameters necessary)
-
As a note: The syntax in your Page_Load should be myID.Attributes.Add("href", "default.css") 'At least that's the syntax in VB.NET Sweet, that works well and keeps me from that headache. I no longer see the style sheet being applied instantly as I work in Design View, which I liked, but I'd rather work this way than have to remember to change the & back to & each time. Thanks for your solution!
-
Yes, unfortunately I'm use VS 2003 the most recent version that I know of. Any ideas of a work around?
-
It's not a hard problem to duplicate so follow this. Create a new web project with Visual basic.Net Call it the default WebApplication1 or what ever. Go to the WebForm1.aspx that is created and View it in html format (Double Click on WebForm1.aspx) On the bottom of the form designer you see two buttons that allow you to switch between Design view and HTML view. Switch to the HTML view since it default to start up in the Design view. Add this line: <link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' > Which will link the cascading style sheet to the web page for your usage. I typically add this line between the <HEAD> and </HEAD> tags. For example: <HEAD> <title>WebForm1</title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name=vs_defaultClientScript content="JavaScript"> <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5"> <!-- I ADDED THE LINE BELOW --> <link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' > </HEAD> This allows me to use the cascading style sheet. Now go back go design view for the WebForm1.aspx Simply drag on a Web Forms Label Control. Or make any modification that causes the form to have that little * appear in the name indicating that the page has been modified. Now switch back to the HTML view of the page and voila the original line now says <link rel=stylesheet type=text/css href='<% Request.ApplicationPath & "/Styles.css" %>' \> Pissing me off... Of course they say better Pissed off than pissed on.
-
Arch4ngel I did this, but it didn't solve my problem. It's still replacing the & with & Thanks though.
-
This is indeed the problem
-
Ok, I'm not sure this is really and ASP.NET problem, it's more of a Visual Studio Environmental problem. VS keeps changing my "&" to "&" on the html portion of my asp.net pages, and of course this is incorrect. I have to do a find and replace for all the & back to & each time I load up a page and this is getting really annoying. I can't find where in the preferences or options to keep visual studio from doing this. Any help would be greatly appreciated. Thanks.
-
Sorry, I should have been more explainatory. I just though since he/she suggested the error he/she would have and idea. I tried simply <% response.redirect "Login.aspx" %> where Login.aspx is in my webroot directory. Looking at the stack trace I noticed it's looking for a sub folder: c:\inetpub\wwwroot\Messages\Login.aspx.vb where Messages was the name of my original project. Is this a namespace issue? I tried setting up a directory on my host server called Messages and placing Login.aspx there, but I'm still getting the same error as before. I'm getting the following error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] JobCenter.frmLogin.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\Messages\Login.aspx.vb:33 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +742 Thank you for any further insite you can provide.
-
Hi, no it does not work. I wrote a simple aspx page with only that one line of code and it didn't work. I'm confused. Do you have any clues? Thanks.
-
I'm coding in ASP.NET with code behinds done in VB.NET. THe ASP.NET program works fine on my local server. However when I try to upload the files to the hosting server my default.aspx page loads fine, but any link buttons that I have that reference any of my pages stopped working. I can't access them using the Response.Redirect(Request.ApplicationPath & "\login.aspx") It keeps saying it can't find the page. I tried hard coding in the full path and it still gives me the error. If I try to access the login.aspx page directly it gives me this error: System.NullReferenceException: Object reference not set to an instance of an object Help!! :confused:
-
I'm trying to learn more about inheritance and was experimenting and can't get this to work. I keep getting the error: Specified argument was out of the range of valid values. Parameter name: '0' is not a valid value for 'index'. What I was experimenting with: I want to take a combo box and fill it with information from my database. As a simple test I tried to do it with States. I put this into a form and it works fine: Dim strStoredProcedure As String = "GetStateCombo" Dim cn As New SqlClient.SqlConnection With cn .ConnectionString = "Server=<SERVERNAME>;Trusted_Connection=false;database=<DBNAME>;user id=<UID>;password=<PASSWORD>" End With Dim cmd As SqlClient.SqlCommand Dim da As New SqlClient.SqlDataAdapter Dim ds As New DataSet cmd = New SqlClient.SqlCommand With cmd .CommandType = CommandType.StoredProcedure .CommandText = strStoredProcedure .Connection = cn End With da.SelectCommand = cmd Try da.Fill(ds) If Not IsNothing(ds) Then ds.Tables(0).TableName = "States" Dim dr As DataRow Me.ComboBox1.DataSource = ds.Tables("States") Me.ComboBox1.DisplayMember = "cboState" Me.ComboBox1.ValueMember = "cboStateCode" End If Catch ex As Exception Throw New Exception(ex.Message, ex) End Try As I said, I'm trying to learn about inheritance. So I decided to design a combo box that automatically inherits from the normal combo box and fills in the states so I can use this in any future project. I call it StateComboBox. So I tried doing this in a class library Public Class StateComboBox 'Here I'm inheriting from the original combo box Inherits System.Windows.Forms.ComboBox Private components As System.ComponentModel.IContainer Protected Overrides Sub Refre****em(ByVal index As Integer) End Sub Protected Overrides Sub SetItemsCore(ByVal items As System.Collections.IList) End Sub Public Sub New() InitializeComponent() FillComboBox() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If (disposing) Then If IsNothing(components) Then components.Dispose() End If MyBase.Dispose(disposing) End If End Sub <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container End Sub Private Sub FillComboBox() Dim strStoredProcedure As String = "GetStateCombo" Dim cn As New SqlClient.SqlConnection("Server=<SERVERNAME>;Trusted_Connection=false;database=<DBNAME>;user id=<UID>;password=<PASSWORD>") Dim cmd As New SqlClient.SqlCommand(strStoredProcedure, cn) Dim da As New SqlClient.SqlDataAdapter Dim ds As New DataSet With cmd .CommandType = CommandType.StoredProcedure End With da.SelectCommand = cmd Try da.Fill(ds) If Not IsNothing(ds) Then ds.Tables(0).TableName = "States" 'THE LINE BELOW THIS COMMENT SEEMS TO BE GENERATING THE ERROR AND THE ERROR APPEARS 2X in a ROW Me.DataSource = ds.Tables("States") Me.DisplayMember = "cboState" Me.ValueMember = "cboStateCode" End If Catch ex As Exception Throw New Exception(ex.Message, ex) End Try End Sub End Class Any help would be appreciated! :confused:
-
Thanks, got it to work. :cool: