I have a need to send text inside richtextbox to projector screen. I have tried to create a new form and make it fullscreen but I cannot yet figure out how I can communicate the text projector as in EasyWorship or PowerPoint. I will appreciate any suggestion. Thanks
I think you don't have to communicate with projector itself.
You can list the available screens, in order to send that form to the correct one (secondary screen). I mean, something like this:
Dim oYourScreen As Screen = nothing
If Screen.AllScreens.Length > 1 Then
For iAux As Integer = 0 To Screen.AllScreens.Length - 1
If Not Screen.AllScreens(iAux).Primary Then
oYourScreen = Screen.AllScreens(iAux)
Exit For
End If
Next
End If
If oYourScreen Is Nothing Then
oYourScreen = Screen.AllScreens(0)
End If
Me.StartPosition = FormStartPosition.Manual
Dim x, y As Integer
x = oYourScreen.Bounds.Location.X + 100 ' adjust as you want
y = oYourScreen.Bounds.Location.X + 30
Me.Location = oYourScreen.Bounds.Location ' or New Point(x, y)
Related
Im a beginer with Visual Basic. Im trying to draw a vertical line on X asix of the chart, but could not find a way to do so. Please advise.
Private Sub Chart()
'Display Chart
Chart1.Series("ScoreChart").Points.Clear()
For xx As Integer = 0 To DataGridView4.RowCount - 1
Me.Chart1.Series("ScoreChart").Points.AddXY(DataGridView4.Rows(xx).Cells(0).Value, DataGridView4.Rows(xx).Cells(DataGridView4.ColumnCount - 1).Value)
Next
End Sub
Like this in the picture
You can refer to the following code to add a vertical line.
Dim verticalLine As VerticalLineAnnotation = New VerticalLineAnnotation()
verticalLine.AxisX = Chart1.ChartAreas(0).AxisX
verticalLine.IsInfinitive = True
verticalLine.ClipToChartArea = Chart1.ChartAreas(0).Name
verticalLine.LineColor = Color.Red
verticalLine.LineWidth = 2
verticalLine.X = 2
Chart1.Annotations.Add(verticalLine)
Result looks like:
I've array of items and for each item, creating a new instance of custom user control. The problem is that when the control is created and added to Flowlayoutpanel, it's not showing up.
Code
Sub createList()
Dim len_ids As Integer = account_ids.Length - 1
Dim x As Integer = 1
While x <= len_ids
Dim listItem As New wrapperItems()
listItem.txtName.Text = account_names(x)
listItem.picIcon.BackgroundImage = Image.FromFile(account_icons(x))
listItem.lblPath.Text = account_paths(x)
listItem.Tag = "listItem" & x
listItem.Top = 10 * x
listItem.Left = 10
Me.flowWrapper1.Controls.Add(listItem)
listItem.Show() ' tried this
listItem.Visible = True 'tried this
listItem.BringToFront() ' tried this
x += 1
End While
Me.Refresh()
End Sub
Anyone has idea of why it's not working?
It seems that when the background worker is started on Form.Show instead of Form.Load, the code doesn't work.
For the fix, I added background worker to Form.Load().
The better way was finally to add a refresh list button and then load the background worker.
I am trying to get a form in a center screen programmatically.
in the codes of Else part is executing perfectly.
Dim X%, Y%
Call FrmCommonCodes.FormLocationXYValues(X, Y)
If X = 100 And Y = 100 Then
'Me.StartPosition = FormStartPosition.CenterScreen
Me.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
Else
Me.Location = New System.Drawing.Point(X, Y)
End If
''FrmCommonCodes.FormLocationXYValues()
Public Sub FormLocationXYValues(ByRef X As Double, ByRef Y As Double)
Using MyConnection As OleDb.OleDbConnection = GetConnection(), MyCommand As New OleDb.OleDbCommand("SELECT * FROM options", MyConnection)
If MyConnection.State = ConnectionState.Closed Then MyConnection.Open()
Using MyDataReader As OleDb.OleDbDataReader = MyCommand.ExecuteReader
While MyDataReader.Read
X = MyDataReader("formlocation_x")
Y = MyDataReader("formlocation_y")
Return
End While
End Using
End Using
End Sub
Looking at your code, what you should do is set the StartPosition property for the form to CenterScreen in the designer. Then if the X and Y coordinates match your default the Form will already be in the right place. That will simplify the code, and fix the problem where setting a start position for a form has no effect if the form has already started:
Dim X As Integer, Y As Integer
Call FrmCommonCodes.FormLocationXYValues(X, Y)
If X <> 100 OrElse Y <> 100 Then
'Default is "CenterScreen", if this code does not run
Me.Location = New System.Drawing.Point(X, Y)
End If
Additionally, you may want to move this code to the Form's constructor, or at least a method that be called before the form is shown. Otherwise, you can see form load up CenterScreen and then jump to the desired location afterwards.
Just one line :
Me.CenterToScreen()
In VB.NET, I need to print multiple Images of bar codes by arranging them in tabular format. For now what I am doing is, Creating the bar codes and adding them in new picture box. These Picture boxes are added on a panel which I am creating on form at run time and print that panel (with picture boxes in 4x9 table).
But, when I need to print more that 36 bar codes, this idea doesn't work.
So, Please suggest me some improvements in my code or any other way to do this job.
I am sorry, here is the code for generating images and adding them to the panel..
''' Method for create bar code images with a loop and adding them to the panel by picture box...
Private Function GetBarcodeText(RowId As Guid)
Dim BarcodeValue As StringBuilder = New StringBuilder(96)
Dim temp As New StringBuilder
Dim data As String
Dim param = New SqlParameter()
Dim imageNo As Integer = 0
Dim colorValue As String = ""
Dim scaleValue As String = ""
'' Adding the panel on the form which is dynamically created
Me.Controls.Add(outputPanel)
'' Setting the Initial size for the panel
outputPanel.Size = New Point(794, 112)
outputPanel.Name = "outputPanel"
outputPanel.BackColor = Drawing.Color.White
param.ParameterName = "#RowId"
param.Value = RowId
param.SqlDbType = SqlDbType.UniqueIdentifier
' Get the particular row of data from database
dt = objStockProvider.GetBarcodeDetails(param)
' GET colour code
Dim color As String = dt.Rows(0)("COLOUR").ToString()
Dim countColors As Integer = 0
' Get the color code numbers
param.ParameterName = "#Dscale"
param.Value = dgvViewTickets.CurrentRow.Cells("SCALE").Value.ToString()
countColors = objStockProvider.CountColorCodes(param)
For i = 1 To countColors
For j As Integer = 1 + ((12 / countColors) * (i - 1)) To (12 / countColors) * i
If dt.Rows(0)("S" + j.ToString()) <> 0 Then
Dim totalTicketsForASize As Integer
totalTicketsForASize = dt.Rows(0)("S" + j.ToString())
For k As Integer = 1 To totalTicketsForASize
' Set Bar code value which has to create
BarcodeValue = "123456789012"
' Create Barcode Image for given value
Dim image = GetBarcodeImage(BarcodeValue, colorValue, scaleValue)
If image IsNot Nothing Then
'' Create picture box to contain generated Image.
Dim pcbImage As New PictureBox
pcbImage.Width = W
pcbImage.Height = H
pcbImage.Image = image
pcbImage.Location = New Point(X, Y)
imageNo += 1
If imageNo Mod 4 = 0 Then
X = 15
Y += H
outputPanel.Height += H
Else
X += W
Y = Y
End If
pcbImage.Visible = True
'' Adding picture box to panel
outputPanel.Controls.Add(pcbImage)
End If
Next
End If
Next
color = color.Substring(color.IndexOf(",") + 1, color.Length - color.IndexOf(",") - 1)
Next
PrintGeneratedTickets()
End Function
Now, I am printing the panel by following method:
Private Sub PrintGeneratedTickets()
bmp = New Bitmap(outputPanel.DisplayRectangle.Width, outputPanel.DisplayRectangle.Height)
Dim G As Graphics = Graphics.FromImage(bmp)
G.DrawRectangle(Pens.White, New Rectangle(0, 0, Me.outputPanel.DisplayRectangle.Width, Me.outputPanel.DisplayRectangle.Height))
Dim Hdc As IntPtr = G.GetHdc()
SendMessage(outputPanel.Handle, WM_PRINT, Hdc, DrawingOptions.PRF_OWNED Or DrawingOptions.PRF_CHILDREN Or DrawingOptions.PRF_CLIENT Or DrawingOptions.PRF_NONCLIENT)
G.ReleaseHdc(Hdc)
pndocument.DocumentName = bmp.ToString()
Dim previewmode As New PrintPreviewDialog
previewmode.Document = pndocument
previewmode.WindowState = FormWindowState.Maximized
previewmode.PrintPreviewControl.Zoom = 1
pndocument.DefaultPageSettings.Margins.Top = 10
pndocument.DefaultPageSettings.Margins.Bottom = 30
pndocument.DefaultPageSettings.Margins.Left = 16
pndocument.DefaultPageSettings.Margins.Right = 16
pndocument.DefaultPageSettings.Landscape = False
' Set other properties.
previewmode.PrintPreviewControl.Columns = 4
previewmode.PrintPreviewControl.Rows = 9
previewmode.ShowDialog()
Dim file As String = DateTime.Now.ToString()
file = Path.GetFullPath("D:\Bar Codes\" + file.Replace("/", "-").Replace(":", ".") + ".bmp")
bmp.Save(file)
G.Dispose()
outputPanel.Controls.Clear()
End Sub
This code is working fine but what I need to do, is to fix the number of images (4x9) per page. But when I am trying to create more than it, that all are printing on a single page with compressed size.
Also when trying to re-run the code, It shows nothing in preview..
Some body please suggest the correction in code so that I can reprint the tickets and use paging for more than 36 images.
Well, Printing the Images on a panel was not a good idea.. I replaced the panel and created an array of images and used the print document directly and print after arranging images on it.
Thanks.
Guys I'm trying to dynamically create panels which are filled with seven radio buttons each.
I get the panels but they are only filled with 1 radio button each. What am I doing wrong here? QuestionQuantity is an Integer and is the variable that determines how many panels I will be creating. The code is in the form load function located.
Thanks,
Dim Pan As Panel
Dim RButton As RadioButton
For x As Integer = 1 To QuestionsQuantity Step 1
Pan = New Panel
Pan.Name = "Panel" & Convert.ToString(x)
Pan.Left = 300
Pan.Top = 100 + 52 * (x - 1)
Pan.Height = 48
Pan.Width = 280
Pan.BackColor = Color.Coral
Controls.Add(Pan)
For y As Integer = 1 To 7 Step 1
RButton = New RadioButton
RButton.Name = "RadioButton" & Convert.ToString(x) & Convert.ToString(y)
RButton.Left = 1 + 30 * (y - 1)
RButton.Top = 10
RButton.Text = Convert.ToString(y)
RButton.CheckAlign = System.Drawing.ContentAlignment.BottomCenter
RButton.TextAlign = System.Drawing.ContentAlignment.TopCenter
RButton.UseVisualStyleBackColor = True
Controls.Add(RButton)
Pan.Controls.Add(RButton)
Next
Next
I messed with it and took out the Panel section and just used the RadioButtons in order to see if i get seven of these. I can get seven if i ofset them in the y direction (.top) but it does not work for some reason in the x (.left) direction
For y As Integer = 1 To 7 Step 1
RButton = New RadioButton
RButton.Name = "RadioButton1" & Convert.ToString(y)
RButton.Left = 20 + (y * 30)
RButton.Top = 10
RButton.Text = Convert.ToString(y)
RButton.CheckAlign = System.Drawing.ContentAlignment.BottomCenter
RButton.TextAlign = System.Drawing.ContentAlignment.TopCenter
RButton.UseVisualStyleBackColor = True
Controls.Add(RButton)
Next
Please help me!
I finally got it. The problem was declaring the size of the RadioButton. It will be too big if not declared even if i make the spacing bigger.
RButton.Size = New System.Drawing.Size(17, 30)
That solved the problem.
You should be using a UserControl that contains your seven radio buttons.
For x As Integer = 1 To QuestionsQuantity
Dim pan As New QuestionUserControl
Pan.Name = "Panel" & Convert.ToString(x)
Pan.Left = 300
Pan.Top = 100 + 52 * (x - 1)
Pan.Height = 48
Pan.Width = 280
Pan.BackColor = Color.Coral
Me.Controls.Add(Pan)
Next
If sticking with your current code, remove this (you should be only adding it to the panel):
For y As Integer = 1 To 7
'// Controls.Add(RButton)
Pan.Controls.Add(RButton)
Next
As far as seeing the control, I'm guessing you aren't going "right" enough:
Dim leftMark As Integer = 20
For y As Integer = 1 To 7
'// code
RButton.Left = leftMark
'//code
leftMark += rButton.Width + 4
Next
with a Pan.Height = 48 there's not going to be much controls inside.
You add the button both to the panel an to Controls ?
Put the radiobuttons in a gridbox. You can dynamically add rows of radiobuttons as you wish. If this will work for you, I'll send a sample code when I get home.