How to draw line programmatically for controls in detail section in crystal report? - vb.net

I want to draw line programmatically for controls in the detail section in a crystal report depending on the amount of data in 3 controls without merging these controls together, I have a working code in access and it is running excellent and I want to use the same code in crystal report but I do not know where to put the code and how I can deal with codes like
for each control in detail.controls
My Code in Access is
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim MaxHt As Single
Dim ctl As Control
MaxHt = Me.Remarks.Height + Me.RemUpdate.Height + Me.Client.Height
'Get maximum height of any control
For Each ctl In Me.Section(acDetail).Controls
If ctl.Height > MaxHt Then
MaxHt = ctl.Height
End If
Next
'Use maximum height to draw rectangles around each control
For Each ctl In Me.Section(acDetail).Controls
Me.Line (ctl.Left, ctl.Top)-(ctl.Left + ctl.Width, MaxHt), vbBlack, B
Next
End Sub
1- I can't find the Detail_Print Event in Crystal Report - I use on Load event (I Don't know if this correct or not)
2- I don't know how to refer to controls in the detail section in crystal report like in Access
example me.Remarks refers to the Remarks Control in Detail Section in Access Report
3- I don't know how to the height or width of control in crystal report field
I checked the web many times and I did not find exact answers
So I need your help
Thanks, Regards

You shouldn't need to do it like that. If you draw a line or box in a report section, one of the formatting options is 'Extend to bottom of section when printing'.

Related

PowerPoint 2010 - VBA to replace figures

I have a slide that we use in my department to provide an overview of the progress regarding project document deliverables. It is shown in a graphic manner, and therefore a simple table view or similar cannot be used. Each of the document deliverables mentioned on the slide can have 3 different legends (figures), a square, triangle and arrow. These are color coded according to stakeholder responsibility of the deliverable. Right now we are changing each one of them manually during the project
What I am looking for:
Is there a VBA code that can easily be used to replace these figures according to project status?
I imagine each Project deliverable needs to be tagged with a position on the slide, and then a userform can be used to select which type of figure there should be assigned?
Anyone who can help me or point me in a direction to something that might help me is highly appreciated!
Thank you
Peter
Here's one approach in rough outline ...
Instead of individual shapes, use a square, triangle and arrow grouped. The user selects the group they want to work with then launches your dialog box where they choose the project status for that item. Your dialog box assigns a value from 1 to 3 to the status then calls SetVisibility like so:
Sub MakeItSo()
Call SetVisibility(2)
End Sub
SetVisibility first makes all of the shapes in the group invisible, then sets the appropriate shape to be visible:
Sub SetVisibility(lStatus As Long)
Dim x As Long
With ActiveWindow.Selection.ShapeRange(1)
For x = 1 To .GroupItems.Count
.GroupItems(x).Visible = False
Next
.GroupItems(lStatus).Visible = True
End With
End Sub

Excel Userform Textbox Constant Set Focus

First of all I would like to thank all of you guys. Maybe you did not notice but you help me to grasp VBA to some level from scratch. I am still in learning process so I may be missing something really simple, please be gentle :)
First of all I would like to give a small backgroud update about my issue. I have been writing a small program to scan incoming parts to my work to be able to keep inventory status. Latest look of the program is like below:
And numbers on the picture are my nightmares lately:
1. Scanned Part Number: This is the textbox where scanner inputs the value. After I receive the input I immidietly convert that data to a variable and clear the textbox value as below:
Private Sub PN_CurrentScan_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
EnteredPN = Replace(PN_CurrentScan.Value, Chr(32), "", 1) '<---PN_CurrentScan is the name of text box
EnteredPN = Left(EnteredPN, 12)
PN_CurrentScan.Value = ""
After making some corrections on the scanned data I basically write it to a sheet in the workbook. Then I also have a pivot table in the same workbook which uses this scanned data as source and counts how many parts scanned from each part number.
2. Current Status: This ListBox contains all the part numbers scanned (Coming from the pivot table mentioned above) and waiting to be scanned (Coming from another worksheet). Then it refreshes it self every time a new part is scanned.
3. ListBox Scroll Bar: Since I have very long part number list it is not possible for me to fit everything on the screen that is why listbox creates this scroll bar.
Enough with the background I think :)
So if we come to my concern. Since my collages using cordless scanner to do this operation sometimes they don't have the chance to see the screen so they can not understand if the cursor is on the "Scanned Part Number Text Box" or not. That is why I need focus to be on that box no matter what happens (Of course we can not do anything if warehouse burns down, earth quake or tsunami hits the place but let do not think about those).
WHAT I HAVE TRIED:
First of all I disabled all the remaining objects from properties window
Then I diabled tab stops of all controls:
Dim contr As Control
For Each contr In ScannerInterface.Controls
On Error Resume Next
contr.TabStop = False
Next
ScannerInterface.PN_CurrentScan.TabStop = True
Added setfocus property to all button clicks:
Me.PN_CurrentScan.SetFocus
Added setfocus property to listbox click:
Private Sub CurrentStatus_List_Click()
Me.PN_CurrentScan.SetFocus
End Sub
Added set focus to enter and exit events of listbox however this did not work:
Private Sub CurrentStatus_List_Enter()
Me.PN_CurrentScan.SetFocus
End Sub
Private Sub CurrentStatus_List_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.PN_CurrentScan.SetFocus
End Sub
So, with all these counter measures I have managed to improve up to somepoint, only concern remaining is when I click on the scroll bar next to the listbox, text box lose focus and without clicking in the textbox I could not manage to set the focus again. I tried all events with listbox non of them worked. Is there any way to solve this problem or do I need to deal with this? Thanks in advance for your supports.
SOLUTION:
Thanks to #Rory we have managed to solve my problem. As he noticed and explained in the answer below, both my textbox and listbox were in frames. I have tried several setfocus options but I always gave the focus to the textbox. However, solution was to give the focus to the frame which was containing the target textbox:
Private Sub CurrentStatus_Frame_Enter() '<-- Enter event of the frame which contains listbox
Me.PN_CurrentScan.SetFocus '<-- Setfocus to target textbox
Me.Scanned_Frame.SetFocus '<-- Setfocus to frame which contains target textbox
End Sub
Having (eventually) noticed that both of your controls are inside container Frame controls, you can actually use the Enter event of the Frame that contains the listbox to set focus to the Frame that contains the textbox, rather than to the textbox itself.

Dynamically Resize forms and controls inspite of change in Display size (Small/Medium/Large) in VB.net

We have developed windows application which is including many forms and controls with default small display size and it is working fine.
but in client systems,displays are not consistent. so when the same code runs with medium/large screen size, the controls are overlapping
It would be great help if anyone gives solution for dynamic re-size/fit the form & controls for any display (small-100%, medium-125%, large-150%)
and also Is there any way to find the Display size (small-100%, medium-125%, large-150%) in vb.net
You can change display size in control-Panel.
You can use the Anchor property to automatically adjust the control size according to its form size. You can anchor any side of the control to that side of the form. For example, if I anchor all four sides of a picturebox to the form, the picturebox will mimic the shape of the form when the form is resized. If you anchor only the top and the bottom of the picturebox, for example, it will change height with the form, but the width and horizontal position will remain constant.
Finally found a solution by doing R&D
call the below function in the Form_Load like ScaleForm(me)
Public Sub ScaleForm(WindowsForm As System.Windows.Forms.Form)
Using g As System.Drawing.Graphics = WindowsForm.CreateGraphics
Dim sngScaleFactor As Single
Dim sngFontFactor As Single = 1
If g.DpiX > 96 Then
sngScaleFactor = g.DpiX / 96
'sngFontFactor = 96 / g.DpiY
End If
If WindowsForm.AutoScaleDimensions = WindowsForm.CurrentAutoScaleDimensions Then
'ucWindowsFormHost.ScaleControl(WindowsForm, sngFontFactor)
WindowsForm.Scale(sngScaleFactor)
End If
End Using
End Sub

How to add a control after another dynamically?

What i am looking for is how to add another control(say a textbox directly under another textbox) that is added through code rather than the designer. I can get it to work using the .height property of the control then adding another 10-20 to it
dim space as integer
space += textbox1.height + 10
however, is there a way to do this on the location rather than the height? In this case, if I want to add a textbox at the very end of the frame or groupbox without having to add additional in between. Since the location takes two parameters(x,y), is it possible to place controls based on another controls location?
Does this help? (not clear what you are after, but yes, you can set the Location or Size all at once):
Dim thisTB as new TextBox
thisTB.Location = new Point(xSpot, ySpot)
thisTB.Size = otherTB.Size
Me.Controls.Add(thisTB)

Looping through dynamically created controls

I have a number of dynamically created buttons (buttons generated at run time), and also a number of dynamically created panels. I want to do something similar to the code below although i know that this code will not work.
For i = 1 to NumberOfButtons
button(i).top = panel(i).top
next
The buttons are named button1, button2 etc. And the panels are also named panel1, panel2 etc.
This is all being written in VB Express 2008.
As you generate your buttons and panels, you need to store them into an array. Then you can access it via index like your have in your code sample. Another option would be to do it via Me.Controls("button1") and similar, but I would consider this bad coding.
For i As Integer = 1 To theTopNumber
Me.Controls("button" & i.ToString).Top = Me.Controls("panel" & i.ToString).Top
Next
Would't this work?
For Each btn As Button In Me.Controls
For Each pnl In Me.Controls
btn.Top = pnl.Top
Next
Next
Please (if you are satisfied) up vote or mark as answer since my mysteriously got banned for no particular reason. It might help to re-enable it :/
;)