I have the following code in ActiveReports 12 in the Designer.vb file. I'm manually upgrading to ActiveReports 16 (because choosing the upgrade option from the Visual Studio menu isn't working) and need to convert all instances of GrapeCity.ActiveReports.SectionReportModel.Picture controls in my reporting files to use ImageBytes instead of ImageData.
The below is valid syntax but does not display the image in the Designer GUI. Any suggestions?
Me.Picture1.ImageBytes = CType(resources.GetObject("Picture1.ImageData"), Byte())
Resources is defined in my InitializeComponent() Sub as:
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ReportFile))
The Picture control is defined in the Designer.vb as follows:
'
'Picture1
'
Me.Picture1.Height = 0.94!
Me.Picture1.ImageData = CType(resources.GetObject("Picture1.ImageData"), System.IO.Stream)
Me.Picture1.Left = 0.0!
Me.Picture1.LineColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(255, Byte), Integer))
Me.Picture1.Name = "Picture1"
Me.Picture1.SizeMode = GrapeCity.ActiveReports.SectionReportModel.SizeModes.Stretch
Me.Picture1.Top = 0.0!
Me.Picture1.Width = 7.94!
Related
I'm working on a windows forms application, using vb.net and microsoft sql server as backend. As for the reports, I'm using microsoft's rdlc, which has been quite satisfactory for me until I was struck with this distinct problem.
So, in the report I'm using external images, which are loaded through local filepaths, passed as parameters. I retrieve these paths from the database and pass it to the report. This method worked for me for a long time, until it stopped working. Now the case is, that the external images are not loading in the report (a red cross is displayed instead of the image). As far as I feel, this problem has something to do with permissions on my PC because the same code and configurations worked for me before, but I'm not able to resolve it. I have searched everywhere to no end and would definitely want assistance.
My code for the report is:
Try
With Me.ReportViewer1.LocalReport
.DataSources.Clear()
.ReportPath = Application.StartupPath & "\RptArticle.rdlc"
.EnableExternalImages = True
Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
Dim imgparameter As New ReportParameter
imgparameter = New ReportParameter("ImagePath", "file://" & imagepathstring, True)
.SetParameters(imgparameter)
Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
Dim barcode As New ReportParameter("Barcode", "file://" & barpathstring, True)
.SetParameters(barcode)
.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleAccessory", Accdt))
.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleSize", AccSdt))
.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleColour", AccCdt))
.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleColour", AccCdt))
.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticle", dt))
End With
Me.ReportViewer1.ZoomMode = ZoomMode.PageWidth
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Me.ReportViewer1.RefreshReport()
When I load the report, the output is:
Warning: Images with external URL references will not display if the report is published to a report server without an UnattendedExecutionAccount or the target image(s) are not enabled for anonymous access. (rsWarningFetchingExternalImages)
Warning: The value of the MIMEType property for the image ‘Image1’ is “application/octet-stream”, which is not a valid MIMEType. (rsInvalidMIMEType)
Warning: The value of the ImageData property for the image ‘Image1’ is “”, which is not a valid ImageData. (rsInvalidExternalImageProperty)
Warning: The value of the MIMEType property for the image ‘Image2’ is “application/octet-stream”, which is not a valid MIMEType. (rsInvalidMIMEType)
Warning: The value of the ImageData property for the image ‘Image2’ is “”, which is not a valid ImageData. (rsInvalidExternalImageProperty)
The thread 0x3948 has exited with code 0 (0x0).
Instead of using external images, you can pass your images as string to your report as parameters.
Convert your image to Base64 string first using this:
Public Function ImageToBase64(ByVal image As Image, ByVal format As System.Drawing.Imaging.ImageFormat) As String
Dim base64String As String = ""
Using ms As New System.IO.MemoryStream()
image.Save(ms, format)
Dim imageBytes As Byte() = ms.ToArray()
base64String = Convert.ToBase64String(imageBytes)
End Using
Return base64String
End Function
So this:
Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
Dim imgparameter As New ReportParameter
imgparameter = New ReportParameter("ImagePath", "file://" & imagepathstring, True)
.SetParameters(imgparameter)
Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
Dim barcode As New ReportParameter("Barcode", "file://" & barpathstring, True)
.SetParameters(barcode)
will be like this:
Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
Dim imgparameter As New ReportParameter
imgparameter = New ReportParameter("ImagePath", ImageToBase64(Image.FromFile(imagepathstring),<THE IMAGE FORMAT OF YOUR IMAGE>))
.SetParameters(imgparameter)
Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
Dim barcode As New ReportParameter("Barcode", ImageToBase64(Image.FromFile(barpathstring),<THE IMAGE FORMAT OF YOUR IMAGE>))
.SetParameters(barcode)
Then, in your report set the following for:
ImagePath
MIMEType = select the correct MIME type from the dropdown list
Source = Database
Value = <Expression>
and in the Expression window:
=System.Convert.FromBase64String(Parameters!ImagePath.Value)
Barcode
MIMEType = select the correct MIME type from the dropdown list
Source = Database
Value = <Expression>
=System.Convert.FromBase64String(Parameters!Barcode.Value)
Hello im creating a media player program on visual studio using vb.net. A basic feature of my application is a simple GUI navigation system, in which the user can select tabs such as 'Home' and 'upload' and a different page will show on each one. To do this i have created user controls, in which i load onto my main form and simply turn visibility to false when not selected.
The problem is i having been getting errors everytime the program is built/ i close and reopen the program.
The designer cannot process unknown name 'BackColor' at line 324. The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.
Viewing this code directs to this chunk-
'
'Uploader_Control2
'
Me.Uploader_Control2.BackColor = System.Drawing.Color.FromArgb(CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer))
Me.Uploader_Control2.Dock = System.Windows.Forms.DockStyle.Fill
Me.Uploader_Control2.Location = New System.Drawing.Point(248, 23)
Me.Uploader_Control2.Name = "Uploader_Control2"
Me.Uploader_Control2.Size = New System.Drawing.Size(1180, 656)
Me.Uploader_Control2.TabIndex = 0
'
'Home_Control2
'
Me.Home_Control2.BackColor = System.Drawing.Color.FromArgb(CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer))
Me.Home_Control2.Dock = System.Windows.Forms.DockStyle.Fill
Me.Home_Control2.Location = New System.Drawing.Point(248, 23)
Me.Home_Control2.Name = "Home_Control2"
Me.Home_Control2.Size = New System.Drawing.Size(1180, 656)
Me.Home_Control2.TabIndex = 1
'
'Uploader_Control1
'
Me.Uploader_Control1.BackColor = System.Drawing.Color.FromArgb(CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer))
Me.Uploader_Control1.Location = New System.Drawing.Point(0, 0)
Me.Uploader_Control1.Name = "Uploader_Control1"
Me.Uploader_Control1.Size = New System.Drawing.Size(1180, 656)
Me.Uploader_Control1.TabIndex = 0
'
'Home_Control1
'
Me.Home_Control1.BackColor = System.Drawing.Color.FromArgb(CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer), CType(CType(24, Byte), Integer))
Me.Home_Control1.Location = New System.Drawing.Point(0, 0)
Me.Home_Control1.Name = "Home_Control1"
Me.Home_Control1.Size = New System.Drawing.Size(1180, 656)
Me.Home_Control1.TabIndex = 0
Deleting this chunk of code removes the error and shows the user controls in my form how i want them. Its starting to become a persistent and annoying issue and despite researching it i have struggled to find any information on how to fix it.
In addition to this loading any of the user controls like this returns a error-
Private Sub Uploader_Control2_Load(sender As Object, e As EventArgs) Handles Uploader_Control2.Load
End Sub
Event load cannot be found
All help appreciated. Thanks in advance.
I am trying to generate a barcode with its text embedded under the very barcode itself but I can only generate the barcode without the text embedded on it.
Here is my code :
Public Function process_printbarcode(lbl169 As Label)
Dim length As Integer = 1
Dim mybarcode As Image = Code128Rendering.MakeBarcodeImage(lbl169.Text.ToString, Integer.Parse(length.ToString()), False)
Admin_Menu.PictureBox3.Image = mybarcode
Return True
End Function
GenCode128 does not include an option to display the encoded value below the barcode as part of the image. You could use the Bitmap and Graphics classes to modify the image and add text to it, but I think it would be easier to just use a different DLL that comes with that functionality. One I've personally used is BarcodeLib. You can add it to your project in a few ways:
Add it as a Nuget Package by running Install-Package BarcodeLib -Version 1.0.0.23 in your package manager console
Download the project's GitHub source-code and build the BarcodeLib.dll yourself
Either way, just add it as a reference in your solution. BarcodeLib has got a lot more barcode parameters available for you to set (and several other encoding types as well), and it's very easy to create them:
Private Function Code128Image(ByVal value As String, _
Optional height As Integer = 100, _
Optional barWidth As Integer = 1, _
Optional labelIncluded As Boolean = True, _
Optional labelPosition As BarcodeLib.LabelPositions = LabelPositions.BOTTOMCENTER, _
Optional barcodeRotation As System.Drawing.RotateFlipType = System.Drawing.RotateFlipType.RotateNoneFlipNone) _
As System.Drawing.Image
Using barcodeImage As New BarcodeLib.Barcode
With barcodeImage
.Height = height
.BarWidth = barWidth
.IncludeLabel = labelIncluded
.LabelPosition = labelPosition
.RotateFlipType = barcodeRotation
Return .Encode(BarcodeLib.TYPE.CODE128, value)
End With
End Using
End Function
Calling Admin_Menu.PictureBox3.Image = Code128Image("123456789") would get you:
I created a SSRS Report which contains a few Code128 Barcodes. The Barcodes are generated using the latest zxing.net library. I would like to include tabs (char(9)) in an Code128 Barcode. But it fail with the following exception message:
System.ArgumentException: Bad character in input:
Needless to say that it works like a charm without the tabulator character.
The GetBarCodeHorizontal is used in the report to generate the barcodes. However, for testing purpose i wrapped it into a visual studio vb project:
Class MainWindow
Public Function GetBarCodeHorizontal(ByVal s As String, ByVal width As Integer) As Byte()
Dim writer As New ZXing.BarcodeWriter()
Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream()
writer.Format = ZXing.BarcodeFormat.CODE_128
writer.Options = New ZXing.Common.EncodingOptions
writer.Options.Width = width
writer.Options.Height = 60
writer.Options.PureBarcode = False
'writer.Options.Hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "UTF-8")
Dim bmp As System.Drawing.Bitmap = writer.Write(s)
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Dim imagedata As Byte()
imagedata = ms.GetBuffer()
Return imagedata
End Function
Private Sub MainWindow_OnLoaded(sender As Object, e As RoutedEventArgs)
Try
Dim barCodeHorizontal = GetBarCodeHorizontal("3999999 80 1XXXXXX8 r1XX3", 200)
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
End Class
Questions:
How can i solve this problem?
Is this a limitation of the zxing library?
Is there any suitable workaround (or maybe even another library)?
I ended up with another (free) library which turns out to work very well.
There is also a tutorial how to embed barcodes into SSRS for this specific library.
For those of interest here is my code to create the barcodes:
Public Function GetBarcode(ByVal text As String, ByVal barcodeWidth As Integer, ByVal barcodeHeight As Integer) As Byte()
Dim b As System.Drawing.Bitmap
Dim bar As New BarcodeLib.Barcode
bar.Alignment = BarcodeLib.AlignmentPositions.CENTER
bar.IncludeLabel = False
b = bar.Encode(BarcodeLib.TYPE.CODE128, text, barcodeWidth, barcodeHeight)
Dim bitmapData As Byte() = Nothing
Using ms As New System.IO.MemoryStream()
b.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
bitmapData = ms.ToArray()
End Using
Return bitmapData
End Function
The barcode data comes directly from the query as shown here:
SELECT MilkrunID, Code, Quantity, Batch, PickLocation, Code + CHAR(9) + CAST(Quantity AS NVARCHAR(20)) + CHAR(9) + Batch + CHAR(9) + PickLocation AS Barcode
FROM Tbl_ReportData_ProductionReplenishment_MilkrunSummary
char(9) creates a Tab.
I'm in the process of writing a little app for our SQL developers to allow them to create labels with TFS for easy code deployment, the trouble is the .ssmssqlproj files are being added to the label when ever i create one. I've added a sub to loop through and unlabel these file but i just will not work. code below
Public Sub UnlabelItem()
Dim returnValue As LabelResult()
Dim labelName As String = "1208-2210"
Dim labelScope As String = "$/"
Dim version As VersionSpec = New LabelVersionSpec(labelName, labelScope)
Dim path As String = "$/FEPI/Database/FEPI/000 Pre Tasks.ssmssqlproj"
Dim recursion As RecursionType = RecursionType.None
Dim itemspec As ItemSpec = New ItemSpec(path, recursion)
returnValue = sourceControl.UnlabelItem(labelName, labelScope, itemspec, version)
End Sub
this is a test Sub just to get it working and this is the error i get
Value of type 'Microsoft.TeamFoundation.VersionControl.Client.ItemSpec' cannot be converted to '1-dimensional array of Microsoft.TeamFoundation.VersionControl.Client.ItemSpec'
HAs anybody had any luck with the unlabel command?
Matt