|
A panel is a control, and those can be drawn to a bitmap. See MSDN[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the advice but that does not create a transparent bitmap and in most cases will not work if the actual drawing to the panel is done through a 3rd party dll.
I think what I really need is more of a screen capture of the panel and then convert its size and transparentcy
|
|
|
|
|
I found this bit of code to work with 2 exceptions. 1) how to re-size it to a smaller image (So I can display a thumbnail type image and 2) how to make the background transparent.
I want item 2 because the image is displayed in a panel control with a black background. That is what the user needs to see. But when I create the image I do not want the black background
Private Sub my_capture(ctrl As Control, fileName As String)
Dim bounds As Rectangle = ctrl.Bounds
Dim pt As Point = ctrl.PointToScreen(bounds.Location)
Dim bitmap As New Bitmap(bounds.Width, bounds.Height)
Using g As Graphics = Graphics.FromImage(bitmap)
g.CopyFromScreen(New Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size)
End Using
bitmap.Save(fileName, ImageFormat.Png)
End Sub
|
|
|
|
|
You'd have to specify which color should become transparent[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I changed my code to this:
But it had no effect. I still get the image with a black background.
I am not sure how to include images with the reply otherwise I would show you before and after images
Dim bounds As Rectangle = ctrl.Bounds
Dim pt As Point = ctrl.PointToScreen(bounds.Location)
Dim myBitmap As New Bitmap(bounds.Width, bounds.Height)
myBitmap.MakeTransparent(ctrl.BackColor)
Using m_g As Graphics = Graphics.FromImage(myBitmap)
m_g.CopyFromScreen(New Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size)
m_g.Dispose()
End Using
myBitmap.Save(fileName, ImageFormat.Png)
myBitmap.Dispose()
|
|
|
|
|
Hi
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Private Sub PrintDocument1_PrintPage(ByVal Sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static page As Integer = 1
Dim startPosition As Integer = (page - 1) * PrintDocument1.DefaultPageSettings.Bounds.Height
Static maxPages As Integer = 0
If page = 1 Then
For Each ctrl As Control In Me.pRight19.Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Or TypeOf ctrl Is PictureBox Or TypeOf ctrl Is RichTextBox Then
ctrl.Tag = Int((ctrl.Top + ctrl.Height) / PrintDocument1.DefaultPageSettings.Bounds.Height) + 1
If CInt(ctrl.Tag) > maxPages Then maxPages = CInt(ctrl.Tag)
End If
Next
End If
For Each ctrl As Control In Me.pRight19.Controls
If CInt(ctrl.Tag) = page Then
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is Label Or TypeOf ctrl Is RichTextBox Then
Dim sf As New System.Drawing.StringFormat
If TypeOf ctrl Is TextBox Then
If DirectCast(ctrl, TextBox).TextAlign = HorizontalAlignment.Right Then
sf.Alignment = StringAlignment.Far
Else
sf.Alignment = StringAlignment.Near
End If
ElseIf TypeOf ctrl Is Label Then
If DirectCast(ctrl, Label).TextAlign = ContentAlignment.TopLeft Then
sf.Alignment = StringAlignment.Far
End If
ElseIf TypeOf ctrl Is RichTextBox Then
If DirectCast(ctrl, RichTextBox).SelectionAlignment = ContentAlignment.TopLeft Then
sf.Alignment = StringAlignment.Near
End If
End If
sf.FormatFlags = StringFormatFlags.NoClip
e.Graphics.DrawString(ctrl.Text, ctrl.Font, New SolidBrush(ctrl.ForeColor), New Rectangle(ctrl.Left, ctrl.Top - startPosition, ctrl.Width + 50, ctrl.Height), sf)
ElseIf TypeOf ctrl Is PictureBox Then
e.Graphics.DrawImage(DirectCast(ctrl, PictureBox).Image, New PointF(ctrl.Left, ctrl.Top - startPosition))
End If
End If
Next
page += 1
If page > maxPages Then
e.HasMorePages = False
page = 1
maxPages = 0
Else
e.HasMorePages = True
End If
End Sub
Private Sub ToolStripButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
' PrintDocument1.Print()
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
|
|
|
|
|
Drago11
I am not sure what all the printing code has to do with my question. Maybe you just pasted it in to the wrong question. Am I missing something?
|
|
|
|
|
That's the good answer, but to the wrong question
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Set the transparency AFTER you capture the screen.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy
yep that is what the issue was. Setting it after did the trick.
Now that I have that working(thanks to you) and I see the results, I think I need to save the image as B/W or greyScale.
Is that difficult?
|
|
|
|
|
Not very hard, but I reckon it will need to remain a 32bit argb format for transparency to work.
There's a howto[^] on MSDN
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hmmm that use the Imaging class
I have seen that used in medical applications I believe,
Maybe I will try a different approach. You would think that Microsoft would of made saving an image a whole lot easier wouln't you?
|
|
|
|
|
I am using the this sub and on the following line of code I get an error
pixColor = myBitmap.GetPixel(x, y)
the error states "An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Drawing.dll
Additional information: Parameter must be positive and < Width."
Would anyone know why?
Private Sub my_capture(ctrl As Control, fileName As String)
Dim bounds As Rectangle = ctrl.Bounds
Dim pt As Point = ctrl.PointToScreen(bounds.Location)
Dim myBitmap As New Bitmap(bounds.Width, bounds.Height)
Dim BW_Bitmap As New Bitmap(bounds.Width, bounds.Height)
Dim x As Integer
Dim y As Integer
Dim pixColor As Color
Dim luma As Integer
Using m_g As Graphics = Graphics.FromImage(myBitmap)
m_g.CopyFromScreen(New Point(pt.X - ctrl.Location.X, pt.Y - ctrl.Location.Y), Point.Empty, bounds.Size)
m_g.Dispose()
End Using
For y = 0 To BW_Bitmap.Height
For x = 0 To BW_Bitmap.Width
pixColor = myBitmap.GetPixel(x, y)
luma = CInt(pixColor.R * 0.3 + pixColor.G * 0.59 + pixColor.B * 0.11)
BW_Bitmap.SetPixel(x, y, Color.FromArgb(luma, luma, luma))
Next
Next
BW_Bitmap.Save(fileName, ImageFormat.Png)
BW_Bitmap.Dispose()
myBitmap.Dispose()
End Sub
|
|
|
|
|
..from 0 to 640, is 641 steps, not 640. That's one more step than there is pixels, causing it to go out of range.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well ! Boy do I feel stupid. Thanks
|
|
|
|
|
how to create ActiveX control
|
|
|
|
|
Considering you haven't told us anything about what you want to do and which flavor of VB you're using, it's pretty much impossible to tell you anything useful.
|
|
|
|
|
We have couple of projects (1 win forms and 1 web form) written in VB.Net. We would like to get those converted into C#. We would be using VS 2012 Professional for BUILD. I am already googling for such tools but would also like to take community's opinion/recommendation on any such highly recommended tools with highest precision/accuracy in converting code from VB.Net to C#. I am good with free and paid tools. Your pointers/suggestions will be highly appreciated.
Thanks in advance.
Regards,
Vipul Mehta
|
|
|
|
|
From what I've seen, most tools work well. But, if the project works, why are you converting it? It is is worthwhile, why not take the time to convert by hand?
The syntax isn't that different, and it is an opportunity to learn.
|
|
|
|
|
All our projects are written in C#. Hence wanted to convert these 2 apps to C#.
Regards,
Vipul Mehta
|
|
|
|
|
I have some code that moves data from an Access database into an Excel spreadsheet. I know that there are easier ways of doing this, but for my particular needs I have to have it moved this way.
The code goes through a query in Access and moves data into the spreadsheet with a loop. That part works just fine.
The problem is that I have to format the spreadsheet with this code. All of the different categories of data will be formatted differently. The piece I am looking at now is called "TheTO."
The code I have moves the data and then goes back and formats cells based on their content. It looks for the words in the cells to do this. The problem is that I will have to repeat this code for about 40 different phrases. That seems excessive to me. Also, if any of those phrases change at all, the code won't work.
I want to have the formatting happen during the loop. However, I don't know how to do that.
Here is the code. I am including one block of the code that is formatting the cells. There would be many, many more because the C.Value will be different every time.
TheTO = rs!to
oSheet.Cells(2, 1).Value = TheTO
TheSTOname = rs!STO
oSheet.Cells(3, 1).Value = TheSTOname
TheStaffName = rs!TeamName
oSheet.Cells(3, 2).Value = TheStaffName
theActDesc = rs!ActDesc
oSheet.Cells(3, 3).Value = theActDesc
rs.MoveNext
Do Until rs.EOF
If rs!to = TheTO Then
If rs!STO = TheSTOname Then
If TheStaffName = rs!TeamName Then
If theActDesc = rs!ActDesc Then
rs.MoveNext
Else
theRow = theRow + 1
oSheet.Cells(theRow, 3).Value = rs!ActDesc
rs.MoveNext
End If
Else
'theRow = theRow + 1
oSheet.Cells(theRow, 2).Value = rs!TeamName
TheStaffName = rs!TeamName
rs.MoveNext
End If
Else
theRow = theRow + 1
oSheet.Cells(theRow, 1).Value = rs!STO
TheSTOname = rs!STO
TheStaffName = ""
rs.MoveNext
End If
Else
theRow = theRow + 1
oSheet.Cells(theRow, 1).Value = rs!to
TheTO = rs!to
rs.MoveNext
End If
skip:
Loop
iNumCols = IIf(w > 0, w, iNumCols)
'Format the header row as bold
With oSheet.Range("a1").Resize(1, iNumCols)
.Font.Bold = True
'Size the columns
.Columns("A:A").ColumnWidth = 40
.Columns("B:B").ColumnWidth = 22
.Columns("C:C").ColumnWidth = 73.44
End With
oSheet.Range("A:A").NumberFormat = "dd-mmm-yy "
With oSheet.Range("A1:" & Chr(iNumCols + 64) & rs.RecordCount + 1)
For Each C In oSheet.Range("A1:" & Chr(iNumCols + 64) & rs.RecordCount + 1).Cells
If C.Value = "First TO" Then
With C
.Font.Name = "Arial"
.Font.Bold = True
.Font.Size = 12
.Interior.ColorIndex = 15
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeTop).ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeBottom).ColorIndex = xlAutomatic
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlEdgeRight).ColorIndex = xlAutomatic
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeLeft).ColorIndex = xlAutomatic
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideVertical).ColorIndex = xlAutomatic
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).Weight = xlThin
.Borders(xlInsideHorizontal).ColorIndex = xlAutomatic
End With
End If
Next C
Thank you, in advance, for any help you can give me!!!!! (I am very new to coding!!)
|
|
|
|
|
You don't need to loop through the Access data to copy it to Excel line by line - Excel has a CopyFromRecordset method[^] which can be used to transfer it in one go.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
The loop is so that the items are listed correctly and do not repeat like they do in the query in Access. I don't know any way to make it look the way it needs to look without the loop.
Any ideas on the formatting?
|
|
|
|
|
Hi all,
I have been working on a script to do what the subject line says but I'm really not getting anywhere. I feel as though I'm almost there, but I just can't figure out the last part.
My script is as follows:
Option Explicit
Dim strProjectsFolder, strProjectNumber, strCostingsPath, strProjectsLTDGroup
strProjectsFolder = "\\ac1fpcov01.za.if.atcsg.net\Business\Delegation IT\Projects\"
strProjectNumber = InputBox("Please enter the new Project Number", "Project Number")
strCostingsPath = strProjectsFolder & strProjectNumber & "\02. Costing"
strProjectsLTDGroup = "AC1-LS-Finance SSC"
SetPermissions
Function SetPermissions()
Dim intRunError, objShell, objFSO
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strCostingsPath) Then
WScript.Echo "You're changing the permissions on " & strCostingsPath
intRunError = objShell.Run ("%COMSPEC% /c Echo Y| ICACLS.EXE " & strCostingsPath & " /inheritance:d /remove:g AC1-LS-Finance SSC:(OI)(CI) ", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error removing inheritance from " & strCostingsPath
End If
Else
WScript.Echo "Error: Project Folder " & strProjectNumber & " does not exist."
End If
End Function
WScript.Quit
I've REMd some lines to simplify while I debug, so I'm currently focusing on the removal of inheritance. I figured if I got that bit right I could move onto the removal of permissions, either in a second IF statement or in the same command line.
But basically, what the script is doing is:
1. Ask the user for the Project number (e.g. P33333)
2. Set variables for the file / folder location based on the project folder on the server
3. Check that the project folder exists, and show a message with the subfolder on which the permissions are being changed.
4. Run the ICACLS command with the /inheritance /T switch to disable inheritance on the project subfolder and all subfolders and files.
5. I've included inRunError to capture any errors, and added another IF statement to show which part of the script is showing the error (only the inheritance section is active at the moment).
6. Finally, an Error trap in case the project folder was entered incorrectly.
Run the script, and all I get is the inRunError that the inheritance command isn't working.
I've taken the exact same command and entered it into a bat file and it works perfectly fine. But in a script it fails every time. I've tried taking all the variables out and working with a skeleton script and still nothing.
So it leads me to believe that I'm either trying to do something with the command that isn't possible, or vbscript just doesn't like me.
Any help would be greatly appreciated.
Thanks
Chris
PS. I should also add, clearly the folder is on a network location. My user account does already have full control permissions over the folder.
It is also an AD security group that I am changing the permissions of in the second part of the script, again it works as-is in a bat file, but not in the script.
|
|
|
|
|
I see you are feeding the stdin of the command-line using the echo command. Two things I would try;
- Try feeding stdin by feeding it from a textfile; one can write stdout to file by routing it (e.g., dir /s >folders.txt), but one can also route stdin. (format <input.txt).
<li>Instead of executing the command with its switches, generate a single batch-file that holds that command as a text, execute it, and delete it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|