|
are you a malayalee, why are you bullying people
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
Xandip wrote: i hav some huge amount of data loading into a grid...
Why? The user only has so much screen space...
Xandip wrote: so i want to show a progresbar which shows the % completed
This depends on where your code is spending all of it's time waiting. It 's waiting for a database query to return, there's nothing you can do to make a ProgressBar work. You need to use something that actually returns data in chunks in order for a ProgressBar to work. You can fill a DataSet object yourself using a DataReader, like this example[^], but this method is slower and will take longer to build your DataSet.
Another version of a ProgressBar doesn't really show progress. Instead, it just shows something is going on, kind of like the Windows XP installation "little green boxes" that march along during the install. They don't show actual progress, just something that's moving to show that the machine hasn't locked up. You can find an example of this here[^].
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi,
I'm trying to use GDI to make a bitmap from a variety of other bitmaps. I'm new to vb2005 from vb6, and I've figured out how to bitblt from one hDC to another, and get the resulting graphics to appear.
What I want to know is how to display a transparent bitmap, based on an alpha channel. I can use an alpha mask, but this doesn't seem to work for shades of grey. I keep seeing code snippets that set a global transparency for your image to be used, but I need transparency per pixel, and at least 255 shades so that it blends or completely covers the bitmap underneath. I'm going to be using multiple images that overlay to make a final image. I'm fine with the graphics side of it, I know how to make alpha layers for PNG's etc and how they work. I just can't code it in.
This code is not complete - it's been cut out to show the basic method I'm using. I'm copying a variety of graphics into a 'master graphic', then stretching that result into the size I require on my form (so it will cope at any resized form)
HDC4 is a small graphic to paste into HDC3 (my 'master image') - HDC4 is what I want to have transparency with
HDC5 is the stretched target
Dim PictSrc As New Bitmap(texture(1)) 'Picture that goes from file to memory<br />
Dim PictMem As Graphics = Graphics.FromImage(PictSrc)<br />
Dim HDC4 As IntPtr = PictMem.GetHdc<br />
<br />
BitBlt(HDC3, xpos, ypos, 100, 75, HDC4, 0, 0, &HEE0086)<br />
<br />
StretchBlt(HDC5, 0, 0, Ship_Systems_Graphic.Width, Ship_Systems_Graphic.Height, HDC3, 0, 0, 453, 192, &HCC0020)<br />
<br />
Any help is appreciated.
www.c-digital-art.co.uk
|
|
|
|
|
Hi
1) Can anyone help me with how to structure some code that if something has not happened in a certain time, the function will return 'False'. The example 'Test0' below must be bad because I am constantly sitting in a loop checking the Port Pin.
2) Is there a better way to use a Timer in 'Test1'?
3) Which routines should be at the Top of the code. Since the routine 'DoTests' is the main loop, I have put it at the top - then as the tests are called, so you find the routines further down in the code. It obviously works anyway around, but I have often noticed in other code examples that the main routine is at the bottom of all the code.
4) After the tests are done (Pass or fail, the routine 'DisplayError is called from the 'DoTests' routine. 'Display Error' in turn calls 'DoTests'. In other words they are constantly calling each other. Is this bad?
Any comments on how I can make this code better will be appreciated..
Example:
Private Sub DoTests()
Test0()
If Not Test1() Then
DisplayError(1)
End If
If Not Test2() Then
DisplayError(2)
End If
DisplayError(10) 'All Tests Passed
End Sub
'Loop until Jig Closes (D0 = 0) to start tests
Private Function Test0() As Boolean
Do While LPTPort.GetState(D0) = 1
Loop
Return True
End Function
Private Function Test1() As Boolean
Dim tmrTestTimeout As Windows.Forms.Timer
tmrTestTimeout.Interval = 3000
tmrTestTimeout.Enabled = True
'Wait for LPTPort pin D1 to go low OR timeout
Do While tmrTestTimeout.Enabled
If LPTPort.GetState(D1) = 0 Then
tmrTestTimeout.Enabled = False
Return True
End If
Loop
'Timed out - so Return False
tmrTestTimeout.Enabled = False
Return False
End Function
Private Sub DisplayError(ByVal intErrorCode As Integer)
Select Case (intErrorCode)
Case 1
Me.lblTestStatus.Text = "Test 1 Failed"
Case 2
Me.lblTestStatus.Text = "Test 2 Failed"
Case 10
Me.lblTestStatus.Text = "All Tests Passed"
Case Else
Me.lblTestStatus.Text = "Unknown Error - Test Aborted"
End Select
'Wait for Jig to open (D0 = 0) so last unit tested is removed
Do While LPTPort.GetState(D0) = 1
Loop
DoTests()
End Sub
|
|
|
|
|
I think it is a much better idea to have an actual counter in the loop and only wait a max amount of time. It also is a good idea to Application.DoEvents while you are in a loop or your form won't refresh.
dim cnt as Integer = 0
Do While (Your normal check here) AndAlso cnt < 100000
'do your other code here
System.Threading.Thread.Sleep(500)
Application.DoEvents
cnt = cnt + 1
Loop
If cnt >= 100000 Then
'didn't finish the test...
End If
I would suggest that type of code over a timer. That way you know for sure that you will exit the loop and with the application.DoEvents it won't look like your application has died and isn't coming back.
Hope that helps.
Ben
|
|
|
|
|
Hi
I have a problem with changing printer's paper size to custom paper size(programmatically).
I use PaperSize cunstuctor to create custom paper size and then assign it to PrintDocument.DefaultPageSettings.PaperSize.
this is not change paper size in printer.
Dim pd As PrintDocument = New PrintDocument<br />
Dim pkCustomSize1 As New PaperSize("Custom", 100, 200)<br />
pd.DefaultPageSettings.PaperSize = pkCustomSize1
Please Guide me
Thnaks
|
|
|
|
|
Does the printer support setting custom paper size? Not all do....
(Can't see anything wrong with the code itself)
|
|
|
|
|
Thanks for your reply.My printer support custom paper size.it's model is
**HP LaserJet 1020**
but when i programmatically change the printer paper size it dose not affect on printer's paper size.
thanks for your guide.
|
|
|
|
|
this won't change the printer's pagesize to 100x200 but you will get your printout in the papersize you specified (for that session only).
Vilsad P P
MCTS (Windows Applications) .Net 2.0
|
|
|
|
|
Hi Vilsad
then i must positioning my text and other objects in page to print correctly?
plese guide me with code snipet
thanks
|
|
|
|
|
yes you must position your text to the newly set papersize. and it will print correctly
initialise your variables in beginprint event because this will be called first when you call printdocument.print method. set a variable to calculate the current height and check it with the pagesettings.printablearea.height and the current printing hight should not exeed this printarea height. if you have more to print then set the hasmorepages = true or when you need to finish set it to false.
the printpage event is repeatedly called when you set hasmorepages = true
Note: Track your current printing position and it should not exeed the paper's limit, if the limit crossed then you will get a infinite number of pages printed.
Vilsad P P
MCTS (Windows Applications) .Net 2.0 Never bring a sword to a gun fight
|
|
|
|
|
Hi
1) Someone told me a function should have only one exit point - why is this?
2) Is it bad practice to use the input to the function directly. In example below, I compare intInput to a constant (10). Should I first equate intInput to a local variable and then use a local variable in the comparison. Just seems like extra code to use anothe variable?
3) As opposed to using 'Return True' or 'Return False' is it better to
use the function name - E.g. 'Test = False'
Private Function Test(byVal intInput as Integer) as Boolean
If intInput >10 then
Return True
Else
Return False
End If
End Function
-- modified at 5:15 Saturday 5th May, 2007
|
|
|
|
|
friend..
Answer to question 1 : i'm not sure of it.
Answer to question 2 : its a good practise, if u use a temporary variable
inside functions. this keeps the original value safe and secure. dont hesitate to write some more code for this, bcoz its usefull when it comes to large programs..
Answer to question 3 : there are no difference between these two, but it is good to use 'Test = False', becoz thats the correct syntax while writing a function. still it is not mandatory. the code will work...
|
|
|
|
|
Thanks
|
|
|
|
|
RichardBerry wrote: 1) Someone told me a function should have only one exit point - why is this?
It is an ideal but I think most developers are not religious about it. The main reason is maintainability, especially with longer, more elaborate functions. OTOH, in OO code, and in procedural code for that matter, functions should not be too long.
For the example you supply it doesn't matter much. Though it is more concise to write
Return intInput > 10
RichardBerry wrote: 2) Is it bad practice to use the input to the function directly. In example below, I compare intInput to a constant (10). Should I first equate intInput to a local variable and then use a local variable in the comparison. Just seems like extra code to use anothe variable?
No, it's not bad practice if all you're doing is effectively "reading" the input variable, as in your example. It is bad practice to modify the input variable and use the modification for subsequent processing. In this case you should take a copy.
RichardBerry wrote: 3) As opposed to using 'Return True' or 'Return False' is it better to
use the function name - E.g. 'Test = False'
This is VB .NET right? Using Return is the recommended way. Using the function name is retained only for backward compatibility.
Kevin
|
|
|
|
|
RichardBerry wrote: 1) Someone told me a function should have only one exit point - why is this?
A big reason is code maintainability. One way in, one way out. If the code has to be modified, you don't have to hunt down all the exit points in a function to make sure it's returning a good value.
RichardBerry wrote: 2) Is it bad practice to use the input to the function directly. In example below, I compare intInput to a constant (10).
Yes, it is, but not for the reason you think. The first thing a function should normally do, is validate the incomming data. This may require multiple tests on multiple parameters. It may also be helpful to put the validated data in local variables so you know that you're using validated data in the rest of the function code.
RichardBerry wrote: 3) As opposed to using 'Return True' or 'Return False' is it better to
use the function name - E.g. 'Test = False'
No, it's not. Quite the opposite. In some languages, including older versions of VB, you had to assign the return value to the function name. It's far more readable and maintainable to use a Return statement. The "assign to function name" method is still in there for backwards compatibility. I wish it would just go away...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Dave Kreskowiak wrote: One way in, one way out. If the code has to be modified, you don't have to hunt down all the exit points in a function to make sure it's returning a good value.
Excellent point. In this case, it is easiest to have a temporary boolean variable such as result and plug it in with the single return statement...
|
|
|
|
|
Paul Conrad wrote: In this case, it is easiest to have a temporary boolean variable such as result and plug it in with the single return statement...
I use this technique quite regularly.
Kevin
|
|
|
|
|
Kevin McFarlane wrote: I use this technique quite regularly.
And it pretty much works out for the best too
|
|
|
|
|
Many thanks!
By the way - Is it normal to thank someone for their reply on a forum- I feel it's just plain good manners, but on the other hand it clutters the forum...
|
|
|
|
|
RichardBerry wrote: By the way - Is it normal to thank someone for their reply on a forum
Sure it is! It happens so rarely, that it doesn't really clutter up anything.
No problem.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi All,
How to find out a particular Page of a MultipageTiff is
Color or Blak and White ????.
Thanks in advance.
Ram
ram
|
|
|
|
|
what is the shortcut key to disable the code.
I am using mouse to do that it seems a lenghty process
|
|
|
|
|
hi nilish,
this is the shortcut to comment/disable the code
Ctrl + k +c
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
|
|
|
|
|