Solved

Using controls

Posted on 2006-06-08
8
182 Views
Last Modified: 2010-04-23
I am using VB.NET 2005 version.In my Main Form I have Buttons like Close,Find,Add,Delete etc.Instead of using buttons in each form,i call these buttons. and they are working properly.

My Question is when  I click (Ctrl+F) I want to display find form,
 How i do that.

The find will work when i will click the find button,properly.I just want it will work also when i will click (Ctrl+F) .Any button property of find? or any other method
0
Comment
Question by:lincyelias
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:anyoneis
Comment Utility
I'm not clear what you want. Are you saying that you want to call the button click routines in your main form from a sub form, when certain keystroke combinations are pressed?

David
0
 

Author Comment

by:lincyelias
Comment Utility
Sir,

In My main Form I have a Button 'btnFind'.If I Click that btnFind, it will call a function Find().

I also want when I use (Ctrl+F),it must call the function Find().
0
 

Author Comment

by:lincyelias
Comment Utility
Any Button Property can set (Ctrl+F)
0
 
LVL 11

Expert Comment

by:anyoneis
Comment Utility
Try this post - it sounds very similar to what you are looking for:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21857861.html

David
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 11

Expert Comment

by:anyoneis
Comment Utility
Actually, it looks like KeyDown is the event you want to subscribe to, not keypress. As in:

[code]
        void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Console.WriteLine("Control is {0} and KeyValue is {1}", e.Control, e.KeyCode);
            if (e.Control  && e.KeyCode.Equals(Keys.F))
            {
                DoFStuff();
                e.Handled = true;
            }
        }

[/code]

David

Then, when you create a subform:

            Form subForm = new SubForm1();
            subForm.KeyDown += Form1_KeyDown;
            subForm.Show(); // or subForm.ShowDialog()

David
0
 

Author Comment

by:lincyelias
Comment Utility
Sir,

U write the code in C#.in VB.net there is no keydown events.so can you write it in VB.net.
Thank You Sir
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 60 total points
Comment Utility
It is pretty much the same in VB. Here is what I came up with:

Public Class Form1

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Console.WriteLine("Control is {0} and KeyValue is {1}", e.Control, e.KeyCode)
        If e.Control AndAlso e.KeyCode.Equals(Keys.F) Then
            DoCtlFStuff()
            e.SuppressKeyPress = True
            e.Handled = True
        End If
    End Sub

    Private Sub DoCtlFStuff()
        MessageBox.Show("CtlFStuff")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        AddHandler Me.KeyDown, AddressOf Form1_KeyDown
    End Sub


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim subForm As Form = New SubForm1()
        AddHandler subForm.KeyDown, AddressOf Form1_KeyDown
        subForm.Show() ' or subForm.ShowDialog()
    End Sub
End Class


Ciao!
David
0
 

Author Comment

by:lincyelias
Comment Utility
Thank Yoo Sir
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now