需要一个调色板专家 [英] Need a palette expert here
问题描述
下面是一个小而完整的程序,似乎向您显示
无法从剪贴板中检索调色板。
无论是否通过Photoshop或
Photoshop或下面的程序将调色板放在剪贴板上
它允许您从文件或程序中放置调色板剪贴板
并允许您从剪贴板中检索一个。但你会发现
检索到的一个总是没什么
我会感激评论
导入System.Drawing.Imaging
公共类Form1
继承System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
私有组件As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
结束子''新
受保护的重载覆盖子处理(ByVal处理为布尔值)
如果处理则
如果不是(组件什么都没有)那么
components.Dispose()
结束如果
结束如果
MyBase.Dispose(处理)
End Sub''Dispose
#Region" Windows窗体设计器生成的代码"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 =新系统.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 =新的System.Windows.Forms.TextBox
Me.Timer 1 =新的System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
''
''button1
''
Me.button1.Location = New System.Drawing.Point( 186,124)
Me.button1.Name =" button1"
Me.button1.Size = New System.Drawing.Size (130,24)
Me.button1.TabIndex = 2
Me.button1.Text =" Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1,从GIF文件复制调色板到
剪贴板)
''
''button2
''
Me.button2。 Location = New System.Drawing.Point(13,124)
Me.button2.Name =" button2"
Me.button2 .Size = New System.Drawing.Size(156,24)
Me.button2.TabIndex = 2
Me.button2.Text =检索剪贴板调色板
Me.ToolTip1.SetToolTip(Me.button2,从剪贴板中检索调色板)
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name =" button3"
Me.button3.Size = New System.Drawing.Size(130 ,24)
Me.button3.TabIndex = 2
Me.button3.Text ="退出>
''
''TextBox1
''
我.TextBox1.Location = New System.Drawing.Point(12,24)
Me.TextBox1.Multiline = True
Me.TextBox1 .Name =" TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304,47)
我。 TextBox1.TabIndex = 3
Me.TextBox1.Text ="可以使用''保存
调色板'将调色板放在剪贴板上按钮或某些 &安培; _
外部程序,如Photoshop
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13,85)
>
Me.TextBox2.Name =" TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302,20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)
Me.ClientSize = New System.Drawing.Size(328,204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name =& Form1
Me.Text =" Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub''InitializeComponent
#End Region
< STAThread()共享子主()
Application.Run(新Form1)
End Sub''Main
Private Sub button1_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理button1.Click
Dim dlg作为新的OpenFileDialog
dlg.Filter =" GIF文件| * .GIF"
如果dlg.ShowDialog()= DialogResult.OK然后
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap,False,CType(zz,Bitmap))
DataO.SetData(DataFormats.Palette.ToString,False,zz .Palette)
Clipboard.SetDataObject(DataO,False)
En d如果
End Sub''button1_Click
Private Sub button2_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(),DataObject)
If DataO .GetDataPresent(DataFormats.Palette,False)然后
cp = CType(DataO.GetData(DataFormats.Palette),ColorPalette)
如果cp什么都没有呢
MessageBox.Show("包含什么都没有的调色板)
Else
MessageBox.Show(cp.ToString)
结束如果
Else
MessageBox.Show(剪贴板上无调色板)
结束如果
结束子''button2_Click
Private Sub button3_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理按钮3.单击
Application.Exit()
End Sub''对接on3_Click
Private Sub Timer1_Tick(ByVal sender As Object,ByVal e As System.EventArgs)
处理Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(),DataObject)
如果是DataO.GetDataPresent(DataFormats.Palette,False)那么
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text ="有剪贴板上的调色板
Else
TextBox2.Text ="剪贴板不包含调色板
结束如果
结束子
结束班''Form1
Below is a small but complete program that appears to show you
can''t retrive a Palette from the clipboard.
This is true whether the palette is placed on the clipboard by Photoshop or
Photoshop or by the below program
It lets you place a palette from a file or from a program on the clipboard
and allows you to retrieve one from the clipboard. But you''ll find the
retrieved one is always "Nothing"
I''d appreciate comments
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
Private components As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub ''New
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub ''Dispose
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
''
''button1
''
Me.button1.Location = New System.Drawing.Point(186, 124)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(130, 24)
Me.button1.TabIndex = 2
Me.button1.Text = "Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1, "Copy Palette from a GIF file to the
clipboard")
''
''button2
''
Me.button2.Location = New System.Drawing.Point(13, 124)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(156, 24)
Me.button2.TabIndex = 2
Me.button2.Text = "Retrieve Clipboard Palette"
Me.ToolTip1.SetToolTip(Me.button2, "Retrieve a palette from the clipboard")
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name = "button3"
Me.button3.Size = New System.Drawing.Size(130, 24)
Me.button3.TabIndex = 2
Me.button3.Text = "Exit"
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(12, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304, 47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Palette can be placed on clipboard by using the ''Save
Palette"" button or by some " & _
"external program such as Photoshop"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13, 85)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302, 20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub ''InitializeComponent
#End Region
<STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub ''Main
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "GIF files|*.GIF"
If dlg.ShowDialog() = DialogResult.OK Then
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap, False, CType(zz, Bitmap))
DataO.SetData(DataFormats.Palette.ToString, False, zz.Palette)
Clipboard.SetDataObject(DataO, False)
End If
End Sub ''button1_Click
Private Sub button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
cp = CType(DataO.GetData(DataFormats.Palette), ColorPalette)
If cp Is Nothing Then
MessageBox.Show("Contains palette that is Nothing")
Else
MessageBox.Show(cp.ToString)
End If
Else
MessageBox.Show("No Palette on Clipboard")
End If
End Sub ''button2_Click
Private Sub button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button3.Click
Application.Exit()
End Sub ''button3_Click
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text = "There is a Palette on the Clipboard"
Else
TextBox2.Text = "The Clipboard does not contain a Palette"
End If
End Sub
End Class ''Form1
推荐答案
DataFormats.Palette是一种私有的剪贴板格式。
也许Microsoft希望这种格式代表新的ColorPalette >
格式但它们提供了一个有缺陷的DataObject类实现。
当您使用GetDataPresent(DataFormats.Palette,
false)或GetDataPresent(DataFormats.Palette,true)查询剪贴板时,返回值为
true。
如果您尝试使用GetData(DataFormats.Palette)检索数据,则
返回值为空。
规范的剪贴板格式是CF_PALETTE,表示为GDI
HPALETTE。
我不知道任何使用私有剪贴板格式的应用程序
DataFormats.Palette并将调色板放在剪贴板上作为
ColorPalette对象。
DataObject类的Microsoft实现不要将
GDI HPALETTE转换为ColorPalette对象。
你需要自己做这件事。
使用P-Invoke使用CF_PALETTE剪贴板格式获取HPALETTE,并使用GDI函数将
转换为新的ColorPalette对象GetObject
an d GetPaletteEntries。
"活性" < ac ********** @ a-znet.comwrote in message
news:OI ************** @ TK2MSFTNGP04.phx .gbl ...
The DataFormats.Palette is a private clipboard format.
Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.
When you query the clipboard using GetDataPresent( DataFormats.Palette,
false) or GetDataPresent( DataFormats.Palette, true), the return value is
true.
If you try to retrieve the data using GetData(DataFormats.Palette), the
return value is null.
The canonical clipboard format is CF_PALETTE which is represented as an GDI
HPALETTE.
I am unaware of any application that uses the private clipboard format
DataFormats.Palette and places the palette on the clipboard as a
ColorPalette object.
The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.
You need to do this on your own.
Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format and
convert it to a new ColorPalette object using the GDI functions GetObject
and GetPaletteEntries.
" active" <ac**********@a-znet.comwrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
下面是一个小而完整的程序,它似乎向您显示
无法从中检索调色板剪贴板。
无论调色板是否通过Photoshop放置在剪贴板上都是真的
或
Photoshop或以下程序
它允许您从文件或剪贴板上的程序中放置调色板
并允许您从剪贴板中检索一个。但你会发现
检索到的一个总是没什么
我会感激评论
导入System.Drawing.Imaging
公共类Form1
继承System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
私有组件As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
结束苏b''新
受保护的重载覆盖子处理(ByVal处理为布尔值)
如果处置则
如果不是(组件什么都没有)那么
components.Dispose()
结束如果
结束如果
MyBase.Dispose(处理)
End Sub''Dispose
#Region" Windows窗体设计器生成的代码"
Private Sub InitializeComponent()
Me.components =新系统。 ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms。按钮
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip( Me.components)
Me.TextBox1 =新的System.Windows.Forms.TextBox
Me.TextBox2 =新的System.Windows.Forms .TextBox
Me.Timer1 =新的System.Windows.Forms.Time r(Me.components)
Me.SuspendLayout()
''
' 'button1
''
Me.button1.Location = New System.Drawing.Point(186,124)
Me.button1.Name =" button1"
Me.button1.Size = New System.Drawing.Size(130,24)
Me.button1.TabIndex = 2
Me.button1.Text =复制文件调色板
Me.ToolTip1.SetToolTip(Me.button1,将调色板从GIF文件复制到
剪贴板)
''
''button2
''
Me.button2.Location = New System.Drawing.Point( 13,124)
Me.button2.Name =" button2"
Me.button2.Size = New System.Drawing.Size (156,24)
Me.button2.TabIndex = 2
Me.button2.Text ="检索剪贴板调色板
Me.ToolTip1.SetToolTip(Me.button2,& 从
剪贴板中检索调色板)
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88,167)
Me.button3.Name =" button3"
Me.button3.Size = New System.Drawing.Size(130,24)
Me.button3.TabIndex = 2
Me.button3.Text ="退出>
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point( 12,24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name =" TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304,47)
Me.TextBox1.TabIndex = 3
>
Me.TextBox1.Text ="可以使用''保存
调色板'将调色板放在剪贴板上按钮或某些 &安培; _
外部程序,如Photoshop
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13,85)
>
Me.TextBox2.Name =" TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302,20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)
Me.ClientSize = New System.Drawing.Size(328,204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name =" Form1
Me.Text =" Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub''InitializeComponent
#End Region
< STAThread()Shared Sub Main()
Application.Run(新Form1)
End Sub''Main
Private Sub button1_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter =" GIF文件| * .GIF"
如果dlg.ShowDialog()= DialogResult.OK那么
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO .SetData(DataFormats.Bitmap,False,CType(zz,Bitmap))
DataO.SetData(DataFormats.Palette.ToString,False,zz.Palette)
/>
Clipboard.SetDataObject(DataO,False)
结束如果
End Sub''butto n1_Click
Private Sub button2_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(),DataObject)
如果是DataO.GetDataPresent(DataFormats.Palette,False)那么
cp = CType(DataO.GetData(DataFormats.Palette),ColorPalette)
如果cp什么都没有那么
MessageBox。显示(包含无任何调色板)
否则
MessageBox.Show(cp.ToString)
结束如果
Else
MessageBox.Show(无剪贴板上的调色板)
结束如果
End Sub''button2_Click
Private Sub button3_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理按钮3.单击
Application.Exit()
End Sub''button3_Click
Private Sub Timer1_Tick( ByVal sender As Object,ByVal e As
System.EventArgs)
处理Timer1.Tick
Dim DataO As DataObject = CType (Clipboard.GetDataObject(),DataObject)
如果是DataO.GetDataPresent(DataFormats.Palette,False)那么
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text ="剪贴板上有一个调色板"
Else
TextBox2.Text ="剪贴板不包含调色板
结束如果
结束子
结束班''Form1
Below is a small but complete program that appears to show you
can''t retrive a Palette from the clipboard.
This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program
It lets you place a palette from a file or from a program on the clipboard
and allows you to retrieve one from the clipboard. But you''ll find the
retrieved one is always "Nothing"
I''d appreciate comments
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
Private components As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub ''New
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub ''Dispose
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
''
''button1
''
Me.button1.Location = New System.Drawing.Point(186, 124)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(130, 24)
Me.button1.TabIndex = 2
Me.button1.Text = "Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1, "Copy Palette from a GIF file to the
clipboard")
''
''button2
''
Me.button2.Location = New System.Drawing.Point(13, 124)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(156, 24)
Me.button2.TabIndex = 2
Me.button2.Text = "Retrieve Clipboard Palette"
Me.ToolTip1.SetToolTip(Me.button2, "Retrieve a palette from the
clipboard")
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name = "button3"
Me.button3.Size = New System.Drawing.Size(130, 24)
Me.button3.TabIndex = 2
Me.button3.Text = "Exit"
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(12, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304, 47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Palette can be placed on clipboard by using the ''Save
Palette"" button or by some " & _
"external program such as Photoshop"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13, 85)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302, 20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub ''InitializeComponent
#End Region
<STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub ''Main
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "GIF files|*.GIF"
If dlg.ShowDialog() = DialogResult.OK Then
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap, False, CType(zz, Bitmap))
DataO.SetData(DataFormats.Palette.ToString, False, zz.Palette)
Clipboard.SetDataObject(DataO, False)
End If
End Sub ''button1_Click
Private Sub button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
cp = CType(DataO.GetData(DataFormats.Palette), ColorPalette)
If cp Is Nothing Then
MessageBox.Show("Contains palette that is Nothing")
Else
MessageBox.Show(cp.ToString)
End If
Else
MessageBox.Show("No Palette on Clipboard")
End If
End Sub ''button2_Click
Private Sub button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button3.Click
Application.Exit()
End Sub ''button3_Click
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text = "There is a Palette on the Clipboard"
Else
TextBox2.Text = "The Clipboard does not contain a Palette"
End If
End Sub
End Class ''Form1
>
我所知道的唯一一种非DotNet方式,我可以用来将调色板放在
剪贴板上,这是我用来测试的。
我执行以下操作并始终获得HPalette = 0
感谢您的信息
公共声明自动功能OpenCl ipboard Lib" user32" (ByVal hWnd As
IntPtr)作为整数
公共声明自动功能GetClipboardData Lib" user32" (ByVal wFormat As
整数)作为IntPtr
Dim HPalette作为IntPtr
Const CF_PALETTE As Integer = 9
如果Wnd.OpenClipboard(IntPtr.Zero)< 0那么
HPalette = Wnd.GetClipboardData(CF_PALETTE)
" Michael Phillips,Jr。" < mp ********* @ nospam.jun0.c0mwrote in message
news:uf ************** @ TK2MSFTNGP03.phx。 gbl ...
The only non-DotNet way that I know of that I can use to put a Palette on
the clipboard is with Photoshop, which is what I use to test.
I do the following and always get HPalette=0
thanks for the info
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer
Public Declare Auto Function GetClipboardData Lib "user32" (ByVal wFormat As
Integer) As IntPtr
Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If Wnd.OpenClipboard(IntPtr.Zero) <0 Then
HPalette = Wnd.GetClipboardData(CF_PALETTE)
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0mwrote in message
news:uf**************@TK2MSFTNGP03.phx.gbl...
DataFormats.Palette是一种私有剪贴板格式。
也许微软希望这种格式代表新的ColorPalette
格式,但它们提供了一个有缺陷的DataObject类实现。
使用GetDataPresent查询剪贴板时(DataFormats.Palette,
false)或GetDataPresent(DataFormats.Palette,true),返回值为
true。
如果您尝试使用GetData(DataFormats.Palette),
返回值为null。
规范的剪贴板格式为CF_PALETTE,表示为
GDI HPALETTE。
我不知道任何使用私有剪贴板格式的应用程序
DataFormats.Palette并将调色板放在剪贴板上作为
ColorPalette对象。
DataObject类的Microsoft实现不会将
GDI HPALETTE转换为ColorPalette对象。
你需要自己做这件事。
使用P-Invoke使用CF_PALETTE剪贴板格式获取HPALETTE和
将其转换为新的ColorPalette对象使用GDI函数GetObject
和GetPaletteEntries。
"活性" < ac ********** @ a-znet.comwrote in message
news:OI ************** @ TK2MSFTNGP04.phx .gbl ...
The DataFormats.Palette is a private clipboard format.
Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.
When you query the clipboard using GetDataPresent( DataFormats.Palette,
false) or GetDataPresent( DataFormats.Palette, true), the return value is
true.
If you try to retrieve the data using GetData(DataFormats.Palette), the
return value is null.
The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.
I am unaware of any application that uses the private clipboard format
DataFormats.Palette and places the palette on the clipboard as a
ColorPalette object.
The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.
You need to do this on your own.
Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format and
convert it to a new ColorPalette object using the GDI functions GetObject
and GetPaletteEntries.
" active" <ac**********@a-znet.comwrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
>下面是一个小而完整的程序,它似乎向您显示
无法从剪贴板中检索调色板。
这是否适用于Photoshop /
Photoshop或下面的程序将调色板放在剪贴板上
它可以让你放置一个调色板来自文件或
剪贴板上的程序,允许您从剪贴板中检索一个。但是你会发现找到的那个总是没什么
我会很感激评论
Imports System.Drawing.Imaging >
公共类Form1
继承System.Windows.Forms.Form
私有WithEvents button1 As System.Windows.Forms.Button
> Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
私有组件As System.ComponentModel.IContainer >
私有cp作为ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
朋友WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub''新
受保护的重载覆盖Sub Dispose(ByVal disposing as Boolean)
如果不是(组件什么都没有)那么
components.Dispose()
结束如果
MyBase.Dispose(处理)
End Sub''Dispose
#Region" Windows窗体设计器生成的代码"私有Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
我。 ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 =新系统。 Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
>''
''button1
''
Me.button1.Location = New System.Drawing.Point(186,124)
Me.button1.Name =" ; button1"
Me.button1.Size = New System.Drawing.Size(130,24)
Me.button1.TabIndex = 2
> Me.button1.Text =" Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1," Copy Palette from a GIF file to the
clipboard)< br />
''
''button2
''
Me.button2.Location = New System.Drawing.Point( 13,124)
Me.button2.Name =" button2"
Me.button2.Size = New System.Drawing.Size(156,24)
Me.button2.TabIndex = 2
Me.button2.Text =检索剪贴板调色板
Me.ToolTip1.SetToolTip(Me.button2, 从
剪贴板中检索调色板)
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88,167)
Me.button3.Name =" button3"
Me.button3。 Size = New System.Drawing.Size(130,24)
Me.button3.TabIndex = 2
Me.button3.Text ="退出>
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(12,24)
Me.TextBox1.Multiline = True
Me.TextBox1。 Name =" TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304,47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text ="可以使用''保存
调色板'"调色板放置在剪贴板上。按钮或某些 &安培; _
外部程序,如Photoshop
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13,85)
Me.TextBox2.Name =" TextBox2"
我.TextBox2.Size = New System.Drawing.Size(302,20)
''
' 'Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)
Me.ClientSize = New System.Drawing.Size( 328,204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
我。 Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name =" Form1"
Me.Text =" Form1"
Me.ResumeLayout(False)
我。 PerformLayout()
End Sub''InitializeCompon ent
#End Region
< STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub''Main
私有子按钮1_Click(ByVal发送者为对象,ByVal e As
System.EventArgs)处理按钮1.点击
Dim dlg如新的OpenFileDialog
dlg.Filter =" GIF文件| * .GIF"
如果dlg.ShowDialog()= DialogResult.OK那么
> Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap,False,CType(zz,Bitmap) ))DataO.SetData(DataFormats.Palette.ToString,False,zz.Palette)
Clipboard.SetDataObject(DataO,False)
结束如果
End Sub''button1_Click
Private Sub button2_Click(ByVal sender As Object,ByVal e As
System.EventArgs)Handle button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(),DataObject)
如果DataO.GetDataPresent(DataFormats.Pal) ette,False)然后
cp = CType(DataO.GetData(DataFormats.Palette),ColorPalette)
如果cp什么都没有那么
MessageBox .Show("包含没有任何东西的调色板)
其他
MessageBox.Show(cp.ToString)
结束如果
其他
MessageBox.Show(无剪贴板上的调色板)
结束如果
End Sub''button2_Click <私有子按钮3_Click(ByVal sender As Object,ByVal e As
System.EventArgs)处理按钮3.单击
Application.Exit()
End Sub''button3_Click
Private Sub Timer1_Tick(ByVal sender As Object,ByVal e As
System.EventArgs)
处理Timer1.Tick
> Dim DataO As DataObject = CType(Clipboard.GetDataObject(),DataObject)
如果DataO.GetDataPresent(DataFormats.Palette,False)那么
Dim cp As ColorPalette = CType (DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text ="有剪贴板上的调色板
否则
TextBox2.Text =剪贴板不包含调色板
结束如果>
End Sub
End Class''Form1
>Below is a small but complete program that appears to show you
can''t retrive a Palette from the clipboard.
This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program
It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But you''ll
find the retrieved one is always "Nothing"
I''d appreciate comments
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
Private components As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub ''New
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub ''Dispose
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
''
''button1
''
Me.button1.Location = New System.Drawing.Point(186, 124)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(130, 24)
Me.button1.TabIndex = 2
Me.button1.Text = "Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1, "Copy Palette from a GIF file to the
clipboard")
''
''button2
''
Me.button2.Location = New System.Drawing.Point(13, 124)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(156, 24)
Me.button2.TabIndex = 2
Me.button2.Text = "Retrieve Clipboard Palette"
Me.ToolTip1.SetToolTip(Me.button2, "Retrieve a palette from the
clipboard")
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name = "button3"
Me.button3.Size = New System.Drawing.Size(130, 24)
Me.button3.TabIndex = 2
Me.button3.Text = "Exit"
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(12, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304, 47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Palette can be placed on clipboard by using the ''Save
Palette"" button or by some " & _
"external program such as Photoshop"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13, 85)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302, 20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub ''InitializeComponent
#End Region
<STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub ''Main
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "GIF files|*.GIF"
If dlg.ShowDialog() = DialogResult.OK Then
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap, False, CType(zz, Bitmap))
DataO.SetData(DataFormats.Palette.ToString, False, zz.Palette)
Clipboard.SetDataObject(DataO, False)
End If
End Sub ''button1_Click
Private Sub button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
cp = CType(DataO.GetData(DataFormats.Palette), ColorPalette)
If cp Is Nothing Then
MessageBox.Show("Contains palette that is Nothing")
Else
MessageBox.Show(cp.ToString)
End If
Else
MessageBox.Show("No Palette on Clipboard")
End If
End Sub ''button2_Click
Private Sub button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button3.Click
Application.Exit()
End Sub ''button3_Click
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text = "There is a Palette on the Clipboard"
Else
TextBox2.Text = "The Clipboard does not contain a Palette"
End If
End Sub
End Class ''Form1
我忘记了IsClipboardFormatAvailable线
I forgot the IsClipboardFormatAvailable lines
我所知道的唯一非DotNet方式我可以用来将调色板放在
上剪贴板是用Photoshop,这是我用来测试的。
我做以下操作并且总是得到HPalette = 0
感谢info
公共声明自动功能OpenClipboard Lib" user32" (ByVal hWnd As
IntPtr)作为整数
公共声明自动功能GetClipboardData Lib" user32" (ByVal wFormat
As Integer)As IntPtr
The only non-DotNet way that I know of that I can use to put a Palette on
the clipboard is with Photoshop, which is what I use to test.
I do the following and always get HPalette=0
thanks for the info
Public Declare Auto Function OpenClipboard Lib "user32" (ByVal hWnd As
IntPtr) As Integer
Public Declare Auto Function GetClipboardData Lib "user32" (ByVal wFormat
As Integer) As IntPtr
Public Declare Auto Function IsClipboardFormatAvailable Lib" user32" (ByVal
wFormat As Integer)As Boolean
Public Declare Auto Function IsClipboardFormatAvailable Lib "user32" (ByVal
wFormat As Integer) As Boolean
>
Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
如果IsClipboardFormatAvailable(CF_PALETTE)那么
如果OpenClipboard(IntPtr.Zero)< 0那么
HPalette = GetClipboardData(CF_PALETTE)
" Michael Phillips,Jr。" < mp ********* @ nospam.jun0.c0mwrote in message
news:uf ************** @ TK2MSFTNGP03.phx。 gbl ...
>
Dim HPalette As IntPtr
Const CF_PALETTE As Integer = 9
If IsClipboardFormatAvailable(CF_PALETTE) Then
If OpenClipboard(IntPtr.Zero) <0 Then
HPalette = GetClipboardData(CF_PALETTE)
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0mwrote in message
news:uf**************@TK2MSFTNGP03.phx.gbl...
> DataFormats.Palette是一种私有剪贴板格式。
也许Microsoft希望这种格式代表新的ColorPalette
格式,但它们提供了一个有缺陷的DataObject类实现。
使用GetDataPresent(DataFormats.Palette,
false)或GetDataPresent(DataFormats.Palette,true)查询剪贴板时),返回值
为真。
如果尝试使用GetData(DataFormats.Palette)检索数据,则
返回值为空。
<规范的剪贴板格式是CF_PALETTE,它表示为
GDI HPALETTE。
我不知道任何使用私有剪贴板格式的应用程序
DataFormats.Palette和地方剪贴板上的调色板作为ColorPalette对象。
DataObject cl的Microsoft实现ass不会将GDI HPALETTE转换为ColorPalette对象。
您需要自己动手。
使用P-Invoke来获取HPALETTE CF_PALETTE剪贴板格式
并使用GDI函数将其转换为新的ColorPalette对象。
GetObject和GetPaletteEntries。
"活性" < ac ********** @ a-znet.comwrote in message
新闻:OI ************** @ TK2MSFTNGP04.phx.gbl .. 。
>The DataFormats.Palette is a private clipboard format.
Perhaps Microsoft intended this format to represent the new ColorPalette
format but they provided a flawed implementation of the DataObject class.
When you query the clipboard using GetDataPresent( DataFormats.Palette,
false) or GetDataPresent( DataFormats.Palette, true), the return value
is true.
If you try to retrieve the data using GetData(DataFormats.Palette), the
return value is null.
The canonical clipboard format is CF_PALETTE which is represented as an
GDI HPALETTE.
I am unaware of any application that uses the private clipboard format
DataFormats.Palette and places the palette on the clipboard as a
ColorPalette object.
The Microsoft implementation of the DataObject class does not convert the
GDI HPALETTE to a ColorPalette object.
You need to do this on your own.
Use P-Invoke to get the HPALETTE using the CF_PALETTE clipboard format
and convert it to a new ColorPalette object using the GDI functions
GetObject and GetPaletteEntries.
" active" <ac**********@a-znet.comwrote in message
news:OI**************@TK2MSFTNGP04.phx.gbl...
>>下面是一个小而完整的程序,它似乎向您显示
无法从剪贴板中恢复调色板。无论调色板是通过Photoshop放置在剪贴板上还是通过Photoshop或以下程序放置在剪贴板上都是如此
它允许您放置调色板文件或
剪贴板上的程序,允许您从剪贴板中检索一个。但是你会发现找到的那个总是没什么
我会很感激评论
Imports System.Drawing.Imaging >
公共类Form1
继承System.Windows.Forms.Form
私有WithEvents button1 As System.Windows.Forms.Button
> Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
私有组件As System.ComponentModel.IContainer >
私有cp作为ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
朋友WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub ''New
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub ’’Dispose
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
’’
’’button1
’’
Me.button1.Location = New System.Drawing.Point(186, 124)
Me.button1.Name = " ;button1"
Me.button1.Size = New System.Drawing.Size(130, 24)
Me.button1.TabIndex = 2
Me.button1.Text = "Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1, "Copy Palette from a GIF file to the
clipboard")
’’
’’button2
’’
Me.button2.Location = New System.Drawing.Point(13, 124)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(156, 24)
Me.button2.TabIndex = 2
Me.button2.Text = "Retrieve Clipboard Palette"
Me.ToolTip1.SetToolTip(Me.button2, "Retrieve a palette from the
clipboard")
’’
’’button3
’’
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name = "button3"
Me.button3.Size = New System.Drawing.Size(130, 24)
Me.button3.TabIndex = 2
Me.button3.Text = "Exit"
’’
’’TextBox1
’’
Me.TextBox1.Location = New System.Drawing.Point(12, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304, 47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Palette can be placed on clipboard by using the
’’Save
Palette"" button or by some " &安培; _
"external program such as Photoshop"
’’
’’TextBox2
’’
Me.TextBox2.Location = New System.Drawing.Point(13, 85)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302, 20)
Me.TextBox2.TabIndex = 4
’’
’’Timer1
’’
Me.Timer1.Enabled = True
’’
’’Form1
’’
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub ’’InitializeCompon ent
#End Region
<STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub ’’Main
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "GIF files|*.GIF"
If dlg.ShowDialog() = DialogResult.OK Then
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap, False, CType(zz, Bitmap))
DataO.SetData(DataFormats.Palette.ToString, False, zz.Palette)
Clipboard.SetDataObject(DataO, False)
End If
End Sub ’’button1_Click
Private Sub button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Pal ette, False) Then
cp = CType(DataO.GetData(DataFormats.Palette), ColorPalette)
If cp Is Nothing Then
MessageBox.Show("Contains palette that is Nothing")
Else
MessageBox.Show(cp.ToString)
End If
Else
MessageBox.Show("No Palette on Clipboard")
End If
End Sub ’’button2_Click
Private Sub button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button3.Click
Application.Exit()
End Sub ’’button3_Click
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text = "There is a Palette on the Clipboard"
Else
TextBox2.Text = "The Clipboard does not contain a Palette"
End If
End Sub
End Class ’’Form1
>>Below is a small but complete program that appears to show you
can''t retrive a Palette from the clipboard.
This is true whether the palette is placed on the clipboard by Photoshop
or
Photoshop or by the below program
It lets you place a palette from a file or from a program on the
clipboard and allows you to retrieve one from the clipboard. But you''ll
find the retrieved one is always "Nothing"
I''d appreciate comments
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents button1 As System.Windows.Forms.Button
Private WithEvents button2 As System.Windows.Forms.Button
Private WithEvents button3 As System.Windows.Forms.Button
Private components As System.ComponentModel.IContainer
Private cp As ColorPalette
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Public Sub New()
InitializeComponent()
End Sub ''New
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub ''Dispose
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.button1 = New System.Windows.Forms.Button
Me.button2 = New System.Windows.Forms.Button
Me.button3 = New System.Windows.Forms.Button
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
''
''button1
''
Me.button1.Location = New System.Drawing.Point(186, 124)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(130, 24)
Me.button1.TabIndex = 2
Me.button1.Text = "Copy File Palette"
Me.ToolTip1.SetToolTip(Me.button1, "Copy Palette from a GIF file to the
clipboard")
''
''button2
''
Me.button2.Location = New System.Drawing.Point(13, 124)
Me.button2.Name = "button2"
Me.button2.Size = New System.Drawing.Size(156, 24)
Me.button2.TabIndex = 2
Me.button2.Text = "Retrieve Clipboard Palette"
Me.ToolTip1.SetToolTip(Me.button2, "Retrieve a palette from the
clipboard")
''
''button3
''
Me.button3.Location = New System.Drawing.Point(88, 167)
Me.button3.Name = "button3"
Me.button3.Size = New System.Drawing.Size(130, 24)
Me.button3.TabIndex = 2
Me.button3.Text = "Exit"
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(12, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(304, 47)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "Palette can be placed on clipboard by using the
''Save
Palette"" button or by some " & _
"external program such as Photoshop"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(13, 85)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(302, 20)
Me.TextBox2.TabIndex = 4
''
''Timer1
''
Me.Timer1.Enabled = True
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(328, 204)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.button1)
Me.Controls.Add(Me.button2)
Me.Controls.Add(Me.button3)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub ''InitializeComponent
#End Region
<STAThread()Shared Sub Main()
Application.Run(New Form1)
End Sub ''Main
Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button1.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "GIF files|*.GIF"
If dlg.ShowDialog() = DialogResult.OK Then
Dim zz As Image = Image.FromFile(dlg.FileName)
Dim DataO As New DataObject
DataO.SetData(DataFormats.Bitmap, False, CType(zz, Bitmap))
DataO.SetData(DataFormats.Palette.ToString, False, zz.Palette)
Clipboard.SetDataObject(DataO, False)
End If
End Sub ''button1_Click
Private Sub button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button2.Click
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
cp = CType(DataO.GetData(DataFormats.Palette), ColorPalette)
If cp Is Nothing Then
MessageBox.Show("Contains palette that is Nothing")
Else
MessageBox.Show(cp.ToString)
End If
Else
MessageBox.Show("No Palette on Clipboard")
End If
End Sub ''button2_Click
Private Sub button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles button3.Click
Application.Exit()
End Sub ''button3_Click
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Timer1.Tick
Dim DataO As DataObject = CType(Clipboard.GetDataObject(), DataObject)
If DataO.GetDataPresent(DataFormats.Palette, False) Then
Dim cp As ColorPalette = CType(DataO.GetData(DataFormats.Palette),
ColorPalette)
TextBox2.Text = "There is a Palette on the Clipboard"
Else
TextBox2.Text = "The Clipboard does not contain a Palette"
End If
End Sub
End Class ''Form1
这篇关于需要一个调色板专家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!