first, i don't know what could i possibly write for the "question" field...
i have a button, and i put a label over it, i did that, and transparency and other things are not a problem for me, the problem is, when i take mouse over the label, the button no more has the "effect" which comes when mouse is over it (blue colored in vista/7) so what i wanna do is, somehow make button think the mouse is over it when the mouse is actually over the label (that label is over button), and make it blue..., sorry if you don't get my english :( i don't know how to explain this.
59 8031
forgot to add, i cannot use draw (OnPaint) text over button cause it looks something like this:
Why are you using a label at all?
Why are you not using the text feature of the button?
i want to place the text at different locations, not just in middle..., and it will NOT have only a single line of text (like OK, Cancel or anything else).
Change the TextAlignment property. You can place it in 9 different positions, not just the middle.
You can put a newline in your text to give it line breaks.
I just think your approach of a label over the button is a hack that is already causing you issues. Either use it as-is, or use a custom-draw function.
forgot to add, i cannot use draw (OnPaint) text over button cause it looks something like this:
Then make your custom draw routine more elaborate to do what you want.
the line breaking is a little complexed, i have seen every possibility i could use, and the only way i see is labels..., i cannot draw(OnPaint), cause as you can see in above post, the draw'ed text dose not look good, while label is good..., so......
okay, so i did some tweaking in custom drawing, the problem in drawing is it draws the text more than just 1 time, thats why it looks ugly... so i need a way to clear the old written text when its writing it again, i tried the Clear method in e.Graphics of button OnPaint event, it clears all the graphics but also put a static backround (that it asks in args), but as you can see the button is not only single colored, so... i dont know what to do :| help?
OnPaint should only occur when an area needs to be refreshed/redrawn, such as when an object has been obscured by another window, then returns to visibility.
It really shouldn't be drawing more than once. Sounds like you may be calling it manually as well as the OS calling it - or some other logic problem.
well i don't know, i never call the Refresh or raise event manually in code, the problem what i see is, it is not erasing the previous written text on the button... - e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
-
e.Graphics.DrawString("Sample Drawing...", Font, Brushes.Navy, new PointF(0, 0));
-
//TextRenderer.DrawText(e.Graphics, "Sample Drawing...", Font, new Point(0, 0), Color.Navy);
this is the code i write in OnPaint, the g.DrawString, or TextRenderer both work, and i dont see any difference in both...
But this isn't liquid ink that soaks in and bleeds. As long as the location is the same, and the font is the same, you are drawing the exact same pixels over each other. You could draw it 100 times and it wouldn't become a thicker line.
As a test put in a property that you can test for. The string itself perhaps. If that string is already written, then don't write it again.
If that string is already written, then don't write it again.
How can i check if the string is already written there....
But this isn't liquid ink that soaks in and bleeds. As long as the location is the same, and the font is the same, you are drawing the exact same pixels over each other. You could draw it 100 times and it wouldn't become a thicker line.
I understand but i dont know why and how this is happening, i managed to somehow print text just once it looked good, but when i take mouse over button, it then flickers, so the way i managed to print once was not good...
If that string is already written, then don't write it again.
How can i check if the string is already written there....
Add a property to check. A button already has text property. You can check to see what the .Text of a button is. But if you set it then that becomes the text on the button through the built-in Text writing methods.
You don't like the built-in text writing methods.
So you could *override* the .Text property to use your methods.
Or create a new property so as to not interfer with the .Text property.
Maybe make a "Caption" property for example.
Then you check the new Caption property to see if it is already the same as the text being passed in. If it is, just return without doing anything.
I'm just curious... What is it that you want to do better/different than the built-in text of a button? The built-in features let you change font, color, size, direction, placement. What does the built-in feature lack that you need?
Additionally the built-in features are aware of system wide themes and preferences. If a user has set their system preferences to larger fonts because they have poor vision then a button already reacts to that. Are you going to write your custom methods to do this as well, or are you going to have your program ignore system-wide user preferences?
i didnt understand what u meant by doing the property stuff...
Additionally the built-in features are aware of system wide themes and preferences. If a user has set their system preferences to larger fonts because they have poor vision then a button already reacts to that.
No, i m not going to take that in account, i will ignore "system-wide user prefences'. Actually, i m developing a application sort of Organizer, it has a calander-type interface, when u click on a date it shows events on the date, i wanna display the events in like.. a button for a event... now i have to display the time of event, reoccurence, title and discription, but i cant use label cause then the "effect" of button when mouse is over it is not working..., i use button cause i want that "glow" effect of button.
Sounds like a very ambitious project to tackle this early in your learning.
i didnt understand what u meant by doing the property stuff...
Do you know what a property is?
Have you ever written something that looks like this? -
private string _caption;
-
public string Caption
-
{
-
get
-
{
-
return _caption;
-
}
-
set
-
{
-
if (value != _caption)
-
{
-
// Then it is a new value
-
DoCustomDraw(value);
-
}
-
_caption = value;
-
}
-
}
By the way, that was a hint about your need for a caption property.
i m not doing "early" learning, i know what property is, but i didnt understand what u meant by Text property for textbox, i draw text manually OnPaint event, how can it be in Text property =_=
i didnt understand what u meant by doing the property stuff...
i m not doing "early" learning, i know what property is
Please forgive me for misinterpreting your remark of "I don't understand what you mean by property" as thinking you didn't understand what a property was. Silly me.
So you could *override* the .Text property to use your methods.
... i draw text manually OnPaint event, how can it be in Text property
If the help you are receiving isn't worth reading in it's entirety or thoroughly then I'm done wasting my time by writing it and spelling everything out including the code that you couldn't figure out by description, and guiding you away from bad ideas like labels on top of buttons.
I wish you the best of luck with your current project, and any future projects in the new year.
argh, okay thanks for your help, happy new year btw. Still i think you dont get what problem i have here. I cannot use a variable/property to check if the text is drawn there..., or maybe i am missing something.
or maybe i am missing something
You are missing something.
It's simple. Maybe you are just over thinking it.
You are going to set the property 'Caption' to the text you want on the button. When you set that with a new string that triggers the custom draw. The custom draw references the Caption property to know what text to put on the button.
When you custom draw your text you set a property equal to that string.
That property now holds the last known string drawn on the face of the button.
At the beginning of your custom draw function you check this property to see if it is the string you are about to draw. If the last string drawn is the same as the string you are about to draw then don't draw it.
Just look at the code I gave you - private string _caption;
-
public string Caption
-
{
-
get
-
{
-
return _caption;
-
}
-
set
-
{
-
if (value != _caption)
-
{
-
// Then it is a new value
-
DoCustomDraw(value);
-
}
-
_caption = value;
-
}
-
}
I have no idea what your custom draw routine looks like.
If you need to, add a variable to it of "LastDrawnText".
Set LastDrawnText after drawing the text
At the start of drawing check to see if LastDrawnText == Caption.
If it is then return without drawing.
now i understand, see the code i wrote: -
-
private void task_show_Load(object sender, EventArgs e)
-
{
-
_brush = Brushes.Navy;
-
Date = "Sample Drawing...";
-
}
-
#endregion
-
-
#region properties
-
private string Date
-
{
-
get { return _date; }
-
set
-
{
-
if (value.Equals(_date)) return;
-
-
DrawDate(value);
-
_date = value;
-
}
-
}
-
#endregion
-
-
#region text painting and stuff
-
private void DrawDate(string date)
-
{
-
Graphics g = back.CreateGraphics();
-
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
-
g.DrawString(date, Font, Brush, new PointF(0, 0));
-
//TextRenderer.DrawText(g, "Sample Drawing...", Font, new Point(0, 0), Color.Navy);
-
g.Dispose();
-
}
-
#endregion
-
but now the problem is, as you can see i give Date the value on Load event, but the button redraws immediately after drawing the text.. and... the text disappears..
I had a thought, hopefully this helps...
Can you just override the paint method on a button to do what you want? I've only been loosely following this thread but looking at the image you posted, the following short snippet of code should give you want you want, and let you set it up through the Designer. Feel free to modify in whatever way you like. - class LButton : Button
-
{
-
[Category("Appearance")]
-
public string LabelText { get; set; }
-
-
[Category("Appearance")]
-
public Point LabelLocation { get; set; }
-
-
protected override void OnPaint(PaintEventArgs pevent)
-
{
-
base.OnPaint(pevent);
-
-
if (pevent != null)
-
{
-
pevent.Graphics.DrawString(LabelText, this.Font, Brushes.Black, LabelLocation);
-
}
-
}
-
}
Note: I just used auto-implemented properties to save space in this example... again, you can do what you like in there.
the result is same as previous image...
Oh, haha, well serves me right for not reading the whole thing. I thought you photoshopped that as a demo of what you *wanted*, my mistake!
Let me see if I've understood this correctly, when you mouse over the label (or text on the image), you want the whole button to appear as if it's been moused over? Or just blue?
yes sir, you got it, when i take the mouse over label (that is on button) i want the button to appear like mouse overed.. the "yellow" glow for this button
I've gotta run, but I played around a bit and have something that may help you. I'm trying to take a different approach than you and Thlintoq have been so far, in hopes that a different viewpoint may help out :) - protected override void OnMouseMove(MouseEventArgs mevent)
-
{
-
base.OnMouseMove(mevent);
-
-
Graphics g = this.CreateGraphics();
-
SizeF strSize = g.MeasureString(m_labelText, this.Font);
-
-
RectangleF labelRect = new RectangleF(m_labelLocation, strSize);
-
-
if (labelRect.Contains(new Point(mevent.X, mevent.Y)))
-
{
-
-
}
-
}
I tried setting the background colour when I was over the label and it worked, but it was just colour, not changing the button's state to whatever it would be when the mouse is down. I was looking around via google but ran outta time.
If that was all that's holding you back, sorry... the thread up until now is a little disjointed, at least to me.
Good luck!
I had a thought, hopefully this helps...
Can you just override the paint method on a button to do what you want?
When Vishal said he had already tried a custom draw routine for the button I thought he had done just that: A custom draw routine in a button (derived) control. I had no idea that he was actually trying to fake it by drawing some text from the main part of his application. Since he started out by trying to fake it with a label placed on top of the button I guess I shouldn't have made the assumption.
I said it before and I'll say it again... This project is more than he should be doing at this early stage of learning.
Vishal: I admire that you want to produce something worthwhile, meaningful, productive. It's good to aim big. But we all have to walk before we can run. I don't want to see you get so frustrated that you give up all together.
Vishal: You are missing several basic concepts in this style of programming. - The one I feel very strongly about is that each object whether it be a button, or a form, or a custom class that contains data about your dog... each object is responsible for itself and ONLY itself. It is a black box with inputs and outputs but what is inside and how it works is SUPPOSED to be a mystery to every other object. It is NOT the responsibility of the form to change how the button draws or looks.
- Next comes reusability. If your form is doing all the heavy lifting for your fancy button what happens when you want to use 5 or 6 of those buttons on a form? What happens when you want to use that same kind of button in a different project? Your custom button should be a control in your toolbox that you can drag and drop on any form: Just exactly the way you do with a standard button, or a textbox or a label. If you have to keep doing copy/paste/alter from project to project to project you are never going to be able to create a uniform look, or produce a finished product that just stands on its own without continuous adjustment and fixes.
- Then comes inheritance. You can create a "mammal" class, then a "canine" class that inherits from 'mammal', then a 'poodle' class that inherits from 'canine'. With each inheritance down the line the offspring become more and more specialized. The same is done with controls You can create your own button that INHERITS from the standard button, then make small changes to have to do what you want.
I am NOT suggesting that you give up on this project. But I am suggesting that you not see it as one bit project. You can use this a learning project that can teach you many things if you just carve it up into lots of smaller projects. It helps if you can envision this as a lot of little projects put together. Its like driving from the East Coast of a country to the West Coast. You don't have just point 'A' and point 'B'. You have to break up the trip with lots of smaller milestones. Stop every 500 km for fuel and look at a map. Am I still on course? Do I have everything I need for the next 500 km? But every stop is still pointing at the final goal. Same thing in programming. Learning to make properties is the first stop along the way to making a custom control. The custom control is a component inside one of many larger components. Those larger components come together to make a GUI for one mode of the application. Several GUIs come together to be the entire program.
If you continue to try to attack this program as one bit monster it's going to eat you alive.
Try this:
Make a new project whose sole purpose is to be a custom control, derived from a Button. Make it what you want it to be. Learn about properties. Make this custom button control everything you want it to be.
Then you can use that button in a larger project.
Here is a shot from my own Toolbox. You can plainly see custom controls such as an IPAddressControl whose purpose and behaviour is to handle IP addresses in their proper form like 123.456.789.001 This isn't done by a form Or an LEDclock control. Or a SerialCtrl that handles all of my serial port needs. I promise I' not trying to discourage you or belittle you. I'm just trying to guide you in a direction that is proven and works through the coding community.
tlhintoq, you dont know my programe structure.. i used the "custom" control for button, i used inheritance , its in the toolbox.. and i m NOT in early stage of learning =_=, i been doing all this from past 2 years, i guess early is the first 6 months. But then again, you never stop learning in this vast programming language, and if you ever finish a language you got more of em coming...
Please don't be offended. "Early" to me has nothing to do with time. I certainly don't know near as much as I would like. A person can take 2 years and complete 1 project. Or the same 2 years and complete 100. 1 project might have taught a person 1 thing, or it can teach them 1,000. Some people write a program for the purpose of making mistakes through experience - then re-write it based on that experience - then re-write that. Others keep massaging the original project. Everyone has their own style.
You might be a whiz-bang at databases... or TCP/ip protocol. I don't know. But in *this* area it is fair to say 'early' in your learning based on the approach you took to *this* problem.
I am now bowing out of this thread.
i m not really offended, i agree.. infact.. i did that ... i made a quiz for the re-write... there are like 20 versions of it re-written :P, and i still want a way to draw the text (not ugly way) or make button "think" the mouse is over it while its over label
gary, i didnt really understood your code?
Which part didn't you understand? We'll start there :)
- SizeF strSize = g.MeasureString(m_labelText, this.Font);
-
-
RectangleF labelRect = new RectangleF(m_labelLocation, strSize);
-
-
if (labelRect.Contains(new Point(mevent.X, mevent.Y)))
-
{
-
-
}
what are you exactly trying to do here?
line numbers per code block above...
* (Line 1) g.MeasureString gets the size of the string, in pixels, and stores it in a SizeF object, which is basically the width and the height of the text.
* (Line 3) I create a rectangle starting at the location where I draw my label, and having the width and the height of my text.
* (Line 5) I check to see if my rectangle contains the current mouse location, which is basically the same as saying... - if (mevent.X >= labelRect.Left && mevent.X <= labelRect.Right && mevent.Y >= labelRect.Top && mevent.Y <= labelRect.Bottom)
I forgot to add when I posted this yesterday... In the future, when you're uncertain on things, try MSDN. Usually they can provide a pretty good explanation of what the methods and classes in the .NET Framework do. These ones were pretty basic though, so I wrote 'em out.
how is your code supposed to check if the text is already drawn, i dont get it :S, i just want something that draws clear text like a label control, or some way to make the button think mouse is over it (so it makes that yellow glow) while the mouse actually is over label.., btw! my application's all codes are 99% done (just need some little polishing and optimization), only GUI part is left, and thats... this button thing i am stucked at..
Oh, it doesn't check if the text is already drawn. I'm trying to show you a different approach than what you had.
I'm drawing the text after the button itself draws, every time. As for the glow, I don't know that either, I've been trying to find it but haven't had much time to search. You'd think there would be a way to tell the button which state it's in for drawing, but maybe it just handles that in the base event handlers.
Out of curiosity, does it have to look like it's clicked/highlighted, or can you do something else? The code I gave you up there will detect when the mouse is over the label, so you could put pretty much whatever you want in there.
its like this, its a popup window that comes when you click on a date (its like a calendar interface), this window has all the events listed on that date, now everything is done (the behind-the-scene codes) just "displaying" it is where i m stuck for now, i want to display it like a button for each event, also make it like a button, so when someone clicks it, it opens edit window, just the problem is, i wanna show title, description, time, and reoccurrence of the event on that "button", i made a custom control but as you can see.. i cant find any way to make the button "look/glow" like it would when mouse would be over it instead of label, and when i draw text manually OnPaint it just looks ugly... if you have any other idea of what should i use instead of a button + label (that also looks good) then speak it up! :P. The code you gave.. i don't think it have any use of it here in this situation.
So far as I can tell, text drawn manually looks the same as if you used a label, I'm not sure what you're seeing that's different.
Anyway, I think the only thing I can tell you at this point is to google around, maaaaaybe you'll find something out there. My solution, and I think thlintoq's too, involves making your own custom control. If you don't want to do that, you're going to have to come up with something fairly sneaky and/or elaborate, which means it's your own creation and people can't really help you with it.
Good luck though!
you can see the difference here...
Sample Drawing.. is the drawn text OnPaint
and Sample Label is the label..
Sample drawing looks like it's being drawn in bold... is the font you're giving the Graphics.DrawString method a bold font?
In the example I gave you, the drawn text and the button text looked the same and the Graphics.DrawString method took the font of the button.
i use the Font property of label to draw the text, so the Sample Drawing... is same font as Label, for Brush i use Brushes.Navy.
Then that's very, very odd. I'm definitely not seeing that on my end.
well then what to do now.. i cant make my own "completely" custom draw routine (that is remove button and draw button my own completely), i m screwed that way..
i sent u a private message with link to the .rar containing a sample exe of the application :)
You don't have the custom draw on there, so I can't see the difference. All that's there is the label method.
Like I said though, I honestly don't know how to programmatically set the button's state for drawing, if you even can. The only way I could imagine how to do this would be to overload that draw method to do something different based on external parameters.
You can still use the label if you want, but you're going to have to set a flag on the button when the mouse is over the label and change the way it draws. Or you can sort out why the Graphics.DrawString text comes out different than your button.
This thread aside, it's a nice looking app :) Is this .NET Forms or WPF?
I am late to the party, did someone already suggest firing the mouseover event for the button?
I just tried and it's not working for me, did you try it, Plater? I admit I might be doing it wrong...
Cool idea though!
@gary sent you another private message, with the exe that also draws the text.., and its a .Net Form application :)
@plater welcome to the party (lol)
It's gotta be something you're doing... attached is a screenshot of my button with the graphics drawing the text over a normal button.
As it happens, when I mouse over the button it appears moused over, so no trickery needed :)
How'd you colour your buttons and whatnot? Are you just setting foreground colours, or did you do anything special?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raymond H. |
last post by:
Hello,
1- How to see, in a Label, the URL of a link that the mouse pass over?
(in the WebBrower control in a vb projet).
2- How to create a menu and a submenu via a button Command1? and...
|
by: Steen Gellett |
last post by:
Hey...........is it possible to move a picture around the form with the
mouse ?
I have a form with one picture on it........when I hold down the mouse I
would like the picture to follow the...
|
by: John Champaign |
last post by:
Hi all,
I'm working on an educational applet for a child with special needs.
He's got a bit of a trick to make my life more difficult... To interact
with the applet he needs to click on...
|
by: Raistlin |
last post by:
Hi Guys,
Is there an On Mouse Over event that is available in Access (Ver 200 pro)?
What I'd like to do is change the text in a Label (say DescrLabel) when the
mouse pointer is placed over a...
|
by: jcrouse |
last post by:
I have the following mouse events assigned to a label control. Is the a way
I can tell which mouse button the users has clicked with?
Private Sub lblP1JoyUp_Click(ByVal sender As System.Object,...
|
by: jcrouse |
last post by:
I have created a form designer type application (with a lot of you peoples
helpJ). It has label controls that are draggable at runtime. The user is
also allowed to change some properties such as...
|
by: aam |
last post by:
hi, im trying to figure out how i can program the mouse to automatically
click on a button of a web page that i'm viewing.i do not have control over
the page.i would also like to set up an...
|
by: pigeonrandle |
last post by:
Hi,
I am trying (with little (no) success) to create a transparent form
that can capture mouse events. Put another way, i would like to show
the other windows that are behind my form (like setting...
|
by: tigger |
last post by:
Hi
I have a label called buttonLabel. How do i display the label only when the mouse is over the button? I tried using mouse hover event and use a timer. But the label will disappear after 1 sec....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
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...
| |