加好友 发短信
等级:超级版主
帖子:7258
积分:40785
威望:0
精华:16
注册:2008/8/31 23:23:00
|
[求助] 狐表GDI绘图.DrawString方法如何动态获得画刷的颜色? Post By:2010/2/21 10:29:00 [显示全部帖子]
在狐表设计系统中,希望能让用户自由设置GDI绘图界面的颜色,但通过反复研究,未能实现动态获得画刷的颜色( Brushes.Red,这是红色画刷,这一句的代码是这样的:g.DrawString(gjdm,fnt,Brushes.Red,45,62)) 下面是设置前后的界面对比: 1、这是系统默认界面: 此主题相关图片如下:1.png 2、这是调整后的界面: 此主题相关图片如下:2.png 上面是改变颜色后,点击二折钢筋的按钮生成的结果,其中背景颜色、钢筋图标颜色、标注线颜色动态活动颜色已经实现,因为画笔支持多种格式的颜色( 3、下面是2折钢筋按钮的全部代码,请大家帮助时参考: Vars("钢筋代码") = left(e.Sender.text,1).Replace("焊","HZ") & " " ' if datatables("系统设置").datarows(0)("提示音类型") = "无" then Audio.Stop() else if datatables("系统设置").datarows(0)("提示音类型") = "随机" then dim tsyy As Integer = Rand.Next(11) '生成0到11之间的随机整数 If FileSys.FileExists(Vars("系统文件路径") & tsyy & ".wav") = true Then Audio.play(Vars("系统文件路径") & tsyy & ".wav",AudioPlayMode.Background) End If else If FileSys.FileExists(Vars("系统文件路径") & datatables("系统设置").datarows(0)("提示音类型") & ".wav") = true Then Audio.play(Vars("系统文件路径") & datatables("系统设置").datarows(0)("提示音类型") & ".wav",AudioPlayMode.Background) End If End If End If Dim Multi As String = "A|B|C|D|E|F|G|H|I|JD1|JD2" Dim Values() as String Values = Multi.split("|") For Index As Integer = 0 To Values.Length - 1 if e.Form.ExistControl(Values(Index)) = true e.Form.RemoveControl(Values(Index)) end if Next Dim p As WinForm.Painter = e.Form.Controls("Painter100") Dim g As Graphics = p.Graphics g.Clear(Color.LightSeaGreen) '清除所有内容,并将背景颜色设为黑色 p.Repaint() 灰色部分无需参考 dim sum as Integer dim i as Integer dim lb as Integer = val(left(e.Sender.text,1).Replace("焊","10")) Sum = Tables("单筋定位参数").Compute("Sum(钢筋类别)", "钢筋类别 = " & lb)/lb For tb As Integer = 1 To 99 if e.Form.ExistControl("Painter" & tb)= true e.Form.RemoveControl("Painter" & tb) end if if tb <= Math.Max(sum,25) dim gjdm as String gjdm = lb & format(tb,"000") Dim A As WinForm.Painter A = e.Form.CreateControl("Painter" & tb, ControlTypeEnum.Painter) A.Left =98*((tb-1) mod 5) A.Top = 65*((tb-1)\5) A.Width =97 A.Height =64 A.BackColor = Color.FromARGB(getConfigValue("窗口图库背景色",e.Form.Controls("ColorLabel5").Value)) e.Form.Controls("Panel11").AddControl(A) if tb <= sum p = Forms("单筋翻样操作").controls("Painter" & tb) g = p.Graphics Dim pn As New Pen(Color.FromARGB(getConfigValue("窗口钢筋图标色",e.Form.Controls("ColorLabel1").Value)),2.5) '指定画笔颜色和画笔宽度 Dim pn1 As New Pen(Color.FromARGB(getConfigValue("窗口标注线颜色",e.Form.Controls("ColorLabel2").Value)),1) '指定画笔颜色和画笔宽度 Dim fnt As New Font("宋体",11,FontStyle.Regular) Dim fnt1 As New Font("宋体",11,FontStyle.Bold) p.Cursor = Windows.Forms.Cursors.Hand g.scaletransform(0.8f,0.8f) Dim dr As DataRow For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '直线'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '直线'and [顺序号] = '" & i & "'") g.DrawLine(pn,dr("x1")-9,dr("y1")+25,dr("x2")-9,dr("y2")+25) Next For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '圆'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '圆'and [顺序号] = '" & i & "'") g.DrawArc(pn,dr("x1")-9,dr("y1")+25,dr("直径"),dr("直径"),dr("起始度"),dr("旋转角度")) Next Multi = "A|B|C|D|E|F|G|H|I" Values = Multi.split("|") For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '字注'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '字注'and [顺序号] = '" & i & "'") g.DrawString( Values(i-1),fnt,Brushes.Lime,dr("x1"),dr("y1")+21) Next Multi = "JD1|JD2" Values = Multi.split("|") For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '角注'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '角注'and [顺序号] = '" & i & "'") g.DrawString( Values(i-1),fnt,Brushes.Lime,dr("x1")-19,dr("y1")+25) Next For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '标注线'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '标注线'and [顺序号] = '" & i & "'") g.DrawLine(pn1,dr("x1")-9,dr("y1")+25,dr("x2")-9,dr("y2")+25) Next For i = 1 to DataTables("单筋定位参数").Compute("max(顺序号)","[钢筋代码] = '" & gjdm & "' and [图形类型] = '标注弧'") dr = DataTables("单筋定位参数").Find("[钢筋代码] = '" & gjdm & "' and [图形类型] = '标注弧'and [顺序号] = '" & i & "'") g.DrawArc(pn1,dr("x1")-9,dr("y1")+25,dr("直径"),dr("直径"),dr("起始度"),dr("旋转角度")) Next g.DrawString(gjdm,fnt1,Brushes.Lime,45,62) p.Repaint() end if end if Next 上述代码中,红色部分是需要动态获得画刷颜色的代码行,红色粗体部分是指定画刷颜色的代码。 绿色部分是已经实现获得画笔颜色的代码行,绿色粗体部分是动态指定画刷颜色的代码。 主要原因:画笔支持多种颜色格式,划算却却只能获取画刷颜色( Brushes.Lime,这里不是一个简单的字符型名称,而是一个新的画笔颜色) 4、另外:颜色标签的 ValueChanged事件代码: SaveConfigValue("窗口钢筋图标色",e.Sender.Value) (目的,调整颜色后的属性保证已后打开项目有效) 里是钢筋图标颜色,其它颜色标签都一样。 窗口的AfterLoad事件代码: e.Form.Controls("ColorLabel1").Value = getConfigValue("窗口钢筋图标色",Color.red) e.Form.Controls("ColorLabel2").Value = getConfigValue("窗口标注线颜色",Color.DimGray) e.Form.Controls("ColorLabel3").Value = getConfigValue("窗口标注文字色",FontStyle.Regular) e.Form.Controls("ColorLabel4").Value = getConfigValue("窗口钢筋代码色",Color.red) e.Form.Controls("ColorLabel5").Value = getConfigValue("窗口图库背景色",Color.Black)
|
|