Hi
I have a label which has text that changes dependent on user input using the paint command. Say it says 'Hello World'.
When I drag the form around such that any part of the label goes offscreen, when the label returns to the screen it wants to constantly repaint itself as it returns meaning that, dependent on how fast you drag it back, the label can read 'He He He He Hello World' or 'HHHHHHello World' etc
Is this a known issue and is there a way to prevent it?
The label is simply painted using -
Private Sub MyLabel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyLabel.Paint
-
In order to get it to change appearance it is invalidated when the user clicks a button to tell it to change to some new value. I'm assuming though that there's some core VB process within the painteventargs that triggers when the item gets back to the visible screen that is the root cause of this as all other labels return to the screen just fine.
Thanks!
What if in your Me_Move event you just invalidated the label?
12 2118
It would help to see the code.
Here is some code. It's pretty basic. -
Option Explicit On
-
Imports System.ComponentModel
-
Imports System.Runtime.InteropServices
-
Imports System.Text
-
Imports System.Windows.Forms
-
Imports System
-
Imports System.IO
-
Imports System.Collections
-
Imports System.Threading
-
-
Public Class Form1
-
-
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
-
MyLabel.Invalidate()
-
End Sub
-
-
Private Sub MyLabel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyLabel.Paint
-
Dim upperfont As Font = New Font("Arial", 10, FontStyle.Bold)
-
Dim lowerfont As Font = New Font("Arial", 8, FontStyle.Regular)
-
Dim upperbrush As SolidBrush = New SolidBrush(Color.Black)
-
Dim lowerbrush As SolidBrush = New SolidBrush(Color.FromArgb(17, 17, 17))
-
Dim upperstr As String = myName.Text
-
Dim lowerstr As String = myOccupation.Text
-
Dim uppersize As SizeF = e.Graphics.MeasureString(upperstr, upperfont, e.ClipRectangle.Size)
-
Dim lowersize As SizeF = e.Graphics.MeasureString(lowerstr, lowerfont, e.ClipRectangle.Size)
-
e.Graphics.DrawString(upperstr, upperfont, upperbrush, e.ClipRectangle.X + 3 + ((e.ClipRectangle.Width - uppersize.Width) / 2), e.ClipRectangle.Location.Y + 19)
-
e.Graphics.DrawString(lowerstr, lowerfont, lowerbrush, e.ClipRectangle.X + ((e.ClipRectangle.Width - lowersize.Width) / 2), e.ClipRectangle.Location.Y + 34)
-
End Sub
-
-
End Class
-
Did you try clearing it before redrawing?
Hi Rabbit, I'm learning VB on the job so not sure what you mean by clearing before redrawing. I thought the Invalidate() triggered some kind of clear/redraw? It seems to be redrawing every time the form is moved and fits the label painting to whatever part of the label is showing at the time.
But you're only invalidating once. If it's redrawing, you should try invalidating each time. Probably in the dragdrop event.
Ah ok. Let me investigate the dragdrop - been away for a few days. Thanks Rabbit.
Not sure Dragdrop is the solution - am looking at trying to determine if the form is being moved but apparently there's no way to do that.
The issue is that this is a static label - it cant be moved within the form. It displays perfectly when you move the form all over the screen. It fails when part of the label goes off the screen edge as I assume that when the form realises that a part that was not visible is now visible again it 'paints' the label. It's that event that I need to kill.
Still checking...
You can either subclass the form and look for the WM_MOVE message or use a timer to see if the form has changed location.
Thanks Rabbit. Might take a look at this later.
At the moment I've added a check named offScreen. When the form Move event is being triggered it checks to see if any part of the form is likely to be outside the screen and, if so, offScreen blocks the painting. It repaints when the form is fully on the screen again.
It's ugly and when label is moved off left side of screen the label is missing text til completely back but this is such a minor part of the application it will do. Was hoping for a simple 'don't repaint when label moving back onscreen' function but not available :)
This isn't going to help many people as it's quite bespoke to my needs but this is the gist of the code I'm running with at the moment. -
Private offScreen = 0
-
Private screenWidth As Integer = 99999
-
Private screenHeight As Integer = 99999
-
-
Private Sub Me_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
Dim myScreens() As Screen = Screen.AllScreens
-
For s = 0 To myScreens.Count - 1
-
screenWidth += myScreens(s).Bounds.Width
-
screenHeight += myScreens(s).Bounds.Height
-
Next
-
End Sub
-
-
Private Sub MyLabel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyLabel.Paint
-
If offScreen = 0 then
-
' do the painting
-
End If
-
End Sub
-
-
Private Sub Me_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
-
offScreen = 0
-
If sender.left + Me.Width > screenWidth OrElse sender.top + Me.Height > screenHeight OrElse sender.left < 0 OrElse sender.top < 0 Then offScreen = 1
-
If offScreen = 0 Then
-
MyLabel.Refresh()
-
End If
-
End Sub
-
-
What if in your Me_Move event you just invalidated the label?
Ha! Genius! Was working this harder than needed. Seems to work a charm. Many thanks, Rabbit.
Glad you got it resolved. Good luck with your project.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Vetrivel |
last post by:
Application architecture : Develop interface between two existing
systems,
a. Enterprise CRM system
b. Web based intranet system.
Environment : Intranet
Server : IIS and ASP.
Script :...
|
by: adawson |
last post by:
Hi,
I need to execute some code when form submission is stopped before the
page is returned from the server. For example, a user clicks a button
to submit the form, realizes they've made a...
|
by: Ron Vecchi |
last post by:
I know the math I need to perform on width and height to keep an aspect
ratio but where and how would I implement keeping a set aspect ratio on a
form when a user resizes it. Override OnResize?...
|
by: Steve Bezner |
last post by:
I have an issue in which a link label on a windows form does not draw the
focus rectangle if you programmatically force it to have focus via the
Control.Focus() method.
To duplicate, create...
|
by: bob |
last post by:
Currently i'm writing some low level communication modules in C++ and
is thinking of putting it into a library so that it can be used in C#.
My concern is the performance issue when putting C++...
|
by: Jaikumar |
last post by:
Hi,
1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image.
2) In the UserControl1 i am...
|
by: Roger Ries via DotNetMonster.com |
last post by:
I'm trying to change the text in a label from another form.
lblInfo.Text = "ABC"
Works for the form your currently in but how the heck do you change that
label information from another form.
...
|
by: pargat.singh |
last post by:
Hi Everyone:
I have asimple app as below
using System;
using System.IO;
|
by: abid gee |
last post by:
Please give a kind look on my question. and please comments.
I am Using C# as development tool of Dot Net 2.0.
I wrote a function read_data() that read data from Serial Port
continuously.Till...
|
by: Elphaba31 |
last post by:
Hello Gurus,
I have been tasked with correcting issues with our upgrade(Access97/2000 to Access2007) and essentially know very little about Access (any version) or Visual Basic. Here is my current...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |