473,785 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Control questions

I have a custom Control that is a label, however I inherit from Control...

1) I override onClick and do a DrawFocusRectan gle, that works great. How do
I clear the focus rectangle once something else on the parent is clicked? I
tried to override OnLostFocus and invalidate but that doesn't seem to do it.

2) the control, like i said is a label, how do i override the hotkey
behavior. I.e, if my text is &Help, when I do Alt-H on the parent, i want to
respond to the hotkey, but i can't quite figure it out.

Thanks

May 4 '07 #1
3 2141
On Fri, 04 May 2007 08:52:31 -0700, Nathan Laff <re******@hotma il.com>
wrote:
I have a custom Control that is a label, however I inherit from
Control...

1) I override onClick and do a DrawFocusRectan gle, that works great. How
do I clear the focus rectangle once something else on the parent is
clicked? I tried to override OnLostFocus and invalidate but that doesn't
seem to do it.
Are you actually getting focus when you get the OnClick event? And are
you calling the base methods in your overrides?

It seems to me that it makes more sense to override the OnGotFocus event
handler, just as you override the OnLostFocus event handler. Then you can
track when focus changes and redraw accordingly. If I recall, the base
Control class already handles basic focus-changing issues, so all you
really need is notification when focus changes.

Overriding OnClick, you may be drawing your focus rectangle without
actually having focus. Also, using the OnClick method to deal with focus
changes leaves you open to missing focus changes for other reasons (tab
key, for example).

I find it a little odd that you want your label to even have the focus;
that's unusual behavior for a label. So that's something to think about
too. :)
2) the control, like i said is a label, how do i override the hotkey
behavior. I.e, if my text is &Help, when I do Alt-H on the parent, i
want to respond to the hotkey, but i can't quite figure it out.
Override the OnKeyPress event handler and if you get Alt-H, set the focus
to the next control in the tab order.

That said, since you're basically doing a custom label, you might want to
consider inheriting from the Label control and just overriding the
behavior you want to change (like redrawing and allowing focus on a
label), and you could automatically get things like the Text and
UseMnemonic properties already in a Label control.

Pete
May 4 '07 #2
Thanks. I'll try that.

I'm not inheriting from a Label because it's a transparent control overtop
of an image.
i'm drawing a focus rectangle around it, because it's like a clickable
dropdown menu. i don't want a button there :)

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Fri, 04 May 2007 08:52:31 -0700, Nathan Laff <re******@hotma il.com>
wrote:
>I have a custom Control that is a label, however I inherit from
Control...

1) I override onClick and do a DrawFocusRectan gle, that works great. How
do I clear the focus rectangle once something else on the parent is
clicked? I tried to override OnLostFocus and invalidate but that doesn't
seem to do it.

Are you actually getting focus when you get the OnClick event? And are
you calling the base methods in your overrides?

It seems to me that it makes more sense to override the OnGotFocus event
handler, just as you override the OnLostFocus event handler. Then you can
track when focus changes and redraw accordingly. If I recall, the base
Control class already handles basic focus-changing issues, so all you
really need is notification when focus changes.

Overriding OnClick, you may be drawing your focus rectangle without
actually having focus. Also, using the OnClick method to deal with focus
changes leaves you open to missing focus changes for other reasons (tab
key, for example).

I find it a little odd that you want your label to even have the focus;
that's unusual behavior for a label. So that's something to think about
too. :)
>2) the control, like i said is a label, how do i override the hotkey
behavior. I.e, if my text is &Help, when I do Alt-H on the parent, i
want to respond to the hotkey, but i can't quite figure it out.

Override the OnKeyPress event handler and if you get Alt-H, set the focus
to the next control in the tab order.

That said, since you're basically doing a custom label, you might want to
consider inheriting from the Label control and just overriding the
behavior you want to change (like redrawing and allowing focus on a
label), and you could automatically get things like the Text and
UseMnemonic properties already in a Label control.

Pete
May 4 '07 #3
On Fri, 04 May 2007 10:54:04 -0700, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
[...]
>2) the control, like i said is a label, how do i override the hotkey
behavior. I.e, if my text is &Help, when I do Alt-H on the parent, i
want to respond to the hotkey, but i can't quite figure it out.

Override the OnKeyPress event handler and if you get Alt-H, set the
focus to the next control in the tab order.
I'm sorry...I'm a little tired today, and that answer was wrong in at
least two ways.

First, you won't get key events unless you have focus. The correct place
to handle the event is in the parent form, not the control itself.
Second, you can't get "Alt" information in the KeyPress event. What you
really want is the KeyDown event.

Other than those rather significant errors, I think the answer is fine. :)

Pete
May 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1672
by: Bill Merrill | last post by:
I'm having a problem with a custom-painted panel. Upon resize, it's invalidated, and redrawn properly. It's also double-buffered so there's no flicker. When I resize the control during runtime, it paints fine. However, when the control is docked, and it's parent is expanded, the child isn't properly redrawn. It's being invalidated and OnPaint is properly called, but sometimes the repaint doesn't actually take effect. If you...
8
3195
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn when the control is painted or resized. When the control is drawn it draws also the items found in the collection. So far so good.... I have 3 questions which I'm unable to find a solution
3
2738
by: anon | last post by:
I am having a hard time with makeing what I am trying to do work. I am making a questionaire web app. I have a custom control that has a label and 5 radio buttons. My problem is that each different topic for the questionaire is in a database and each questionaire will have a different number of questions. I am trying to use a repeater to creat multiple copies of the control, unfortunately when I do this the different controls act like...
9
4693
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate> /asp:Repeater> The DataSource for this Repeater is a CollectionBase of objects and is
19
4921
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
3
1156
by: shapper | last post by:
Hello, I am starting to create various custom controls for Asp.Net 2.0 and I am using Visual Studio 2005. I have a few questions: 1. Should I use the Web Site or Project Model? I believe Project Model allows me to embed the resources (images, css files, etc) into my DLL.
6
11082
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
1
1982
by: rizwanahmed24 | last post by:
Hello i have created a custom control. i have placed two template controls on it. One is check box and second is picture box. The custom control also contain two picture boxes as property. These picture boxes can be filled at design time. I want my custom control to act as container. I drag the controls from toolbox on my custom control. Everything is fine so far. But when i compile the application the two template controls i mentioned...
2
5224
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have an existing (WPF) Class Library project that I'd like to add a WPF Custom Control to. However, when I try to Add New Item, that isn't one of the available options. Perhaps this is a brain freeze, but what could I possibly be missing? WtS
4
2492
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.