Custom draw vs Owner draw

18 篇文章 0 订阅

From: http://www.codeproject.com/KB/miscctrl/CustomDrawCSliderCtrl.aspx

http://www.codeproject.com/Articles/8985/Customizing-the-Appearance-of-CSliderCtrl-Using-Cu


"Custom Draw" is a feature shared by all of Microsoft's common controls, which allows you to interject your own code while the control is drawing itself. In this way, you can customize the appearance of the control, altering it to suit your needs and tastes.

There have been a number of great articles on custom draw, in the context of various different controls. One of the best is Michael Dunn's "Neat Stuff to do in List Controls Using Custom Draw", which illustrates how to tame an unruly custom draw interface to customize the appearance of aCListCtrl (which is a common listview control). Other examples and a good explanation can be found at MSDN, beginning with the article "Customizing a Control's Appearance Using Custom Draw".

"Custom Draw" is not the same thing as "Owner Draw". Custom draw notifications are sent out automatically (it's up to you to catch the notifications and process them correctly), whereas for "owner draw", you need to set a style flag (such as LVS_OWNERDRAWFIXED for a list-view control) before the control will send you a WM_DRAWITEM message. In custom draw, the control pretty much draws itself completely, and your code customizes its appearance only here-and-there, whereas for owner draw, you must draw everything, usually in an OnDrawItem handler, even if you want to make the most trivial change. Custom draw is available only for the common controls (like Header controls, List-view controls, Rebar controls, Toolbar controls, ToolTip controls, Trackbar controls, and Tree-view controls) but is not available for the standard (and older) Windows controls (like button controls, combo box controls, list box controls, progress bar controls, static controls, and tab controls); owner draw, on the other hand, is available for all controls.

You can think of custom draw as a kind of "light-weight" owner draw (Michael Dunn's words), where the control does most of the work, and you modify just a bit of it. In the hierarchy of things, if you like the way a control looks and how it functions, then use the control "as is"; if you like most of the way the control looks and how it functions, then use custom draw; if you don't like the way a control looks but you like how it functions, then use Owner draw; and if you don't like the way it looks or the way it functions, then write your own custom control.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Mapbox Draw 是一个用于在 Mapbox 地图上绘制图形的 JavaScript 库。要修改绘制的点、线和面的样式,需要编辑 Mapbox Draw 的样式表。 以下是一个简单的示例,演示如何使用 Mapbox Draw 绘制一个点、一条线和一个多边形,并修改其样式: ```html <!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title>Mapbox Draw Style</title> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> <script src='https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js'></script> <link href='https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.css' rel='stylesheet' /> <script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.3.0/mapbox-gl-draw.js'></script> <link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.3.0/mapbox-gl-draw.css' type='text/css' /> <style> #map { height: 500px; } </style> </head> <body> <div id='map'></div> <script> mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN_HERE'; var map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v11', center: [-122.4194, 37.7749], zoom: 13 }); var draw = new MapboxDraw({ displayControlsDefault: false, controls: { point: true, line_string: true, polygon: true, trash: true }, styles: [ // 修改点的样式 { id: 'custom-point', type: 'circle', paint: { 'circle-radius': 8, 'circle-color': '#ff0000' }, filter: ['in', '$type', 'Point'] }, // 修改线的样式 { id: 'custom-line', type: 'line', paint: { 'line-color': '#00ff00', 'line-width': 4 }, filter: ['in', '$type', 'LineString'] }, // 修改面的样式 { id: 'custom-polygon', type: 'fill', paint: { 'fill-color': '#0000ff', 'fill-opacity': 0.5 }, filter: ['in', '$type', 'Polygon'] } ] }); map.addControl(draw); map.on('draw.create', function(e) { console.log(e.features); }); </script> </body> </html> ``` 在上面的示例中,我们定义了三个不同类型的样式:`custom-point`、`custom-line` 和 `custom-polygon`。通过修改这些样式的 paint 属性,我们可以改变它们的外观。在这个例子中,我们将点的颜色修改为红色,将线的颜色修改为绿色,将面的颜色修改为蓝色,并调整了它们的大小和透明度。 注意,我们还需要在 Mapbox 地图中添加 `mapbox-gl-draw` 控件,以便用户可以在地图上绘制图形。在上面的代码中,我们通过 `map.addControl(draw)` 将 `MapboxDraw` 实例添加到地图上。 当用户在地图上绘制点、线或多边形时,`draw.create` 事件将被触发,并将新绘制的要素作为参数传递给回调函数。在这个例子中,我们简单地将要素打印到控制台上,以便您可以看到它们的结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值