GithubHelp home page GithubHelp logo

增加例程需求 about govcl HOT 7 CLOSED

ying32 avatar ying32 commented on May 17, 2024 2
增加例程需求

from govcl.

Comments (7)

ismlsmile avatar ismlsmile commented on May 17, 2024

1、带CheckBox的TTreeView(lcl不支持的话仅vcl)
2、TListView
(1)Item和SubItem自绘控件:如图片、CheckBox(lcl不支持的话仅vcl)
(2)单元格上色:指定行、指定Item、指定SubItem
3、TStringGrid
(1)排序
(2)自绘控件(如图片、CheckBox)
(3)单元格上色

from govcl.

ying32 avatar ying32 commented on May 17, 2024

@ismlsmile

from govcl.

ismlsmile avatar ismlsmile commented on May 17, 2024

“单元格上色”指的就是给单元格加个背景色。TListView中我发现个比较怪的问题,在SetOnAdvancedCustomDrawItem事件中,只调用:
sender.Canvas().Brush().SetColor(colors.ClRed)
对第一个Item上色后,后面的SubItem都上成同样颜色了。如果只想对第一列的单元格上色,不知道有什么好的办法?当前我测试时发现可以在SetOnAdvancedCustomDrawSubItem事件中把SubItem的颜色再上回去,但感觉方法比较土。

from govcl.

ying32 avatar ying32 commented on May 17, 2024

@ismlsmile TListView的项目就是根据项目的列索引设置Brush的不同颜色

from govcl.

ismlsmile avatar ismlsmile commented on May 17, 2024

比如需求是这样的,只要设置第一列的颜色为红色,但下面的例子中,ListViewAdvancedCustomDrawItem设置后,整行都会变为红色

package main

import (
"fmt"
"github.com/ying32/govcl/vcl"
"github.com/ying32/govcl/vcl/types"
"github.com/ying32/govcl/vcl/types/colors"
"math/rand"
)

func main() {
vcl.Application.Initialize()

mainForm := vcl.Application.CreateForm()
mainForm.SetPosition(types.PoScreenCenter)
mainForm.SetWidth(500)
mainForm.SetHeight(400)

lv1 := vcl.NewListView(mainForm)
lv1.SetParent(mainForm)
lv1.SetAlign(types.AlTop)
lv1.SetRowSelect(true)
lv1.SetReadOnly(true)
lv1.SetViewStyle(types.VsReport)
lv1.SetGridLines(true)

col := lv1.Columns().Add()
col.SetCaption("序号")
col.SetWidth(100)

col = lv1.Columns().Add()
col.SetCaption("项目1")
col.SetWidth(200)

lv1.Items().BeginUpdate()
for i := 1; i <= 20; i++ {
	item := lv1.Items().Add()
	item.SetCaption(fmt.Sprintf("%d", i+rand.Int()))
	item.SubItems().Add(fmt.Sprintf("值:%d", i+rand.Int()))
}
lv1.Items().EndUpdate()

lv1.SetOnAdvancedCustomDrawItem(ListViewAdvancedCustomDrawItem)

vcl.Application.Run()

}

func ListViewAdvancedCustomDrawItem(sender *vcl.TListView, item *vcl.TListItem, state types.TCustomDrawState, Stage types.TCustomDrawStage, defaultDraw *bool) {
sender.Canvas().Brush().SetColor(colors.ClRed)
}

from govcl.

ying32 avatar ying32 commented on May 17, 2024

@ismlsmile 大概这样子吧

package main

import (
	"fmt"
	"math/rand"

	"github.com/ying32/govcl/vcl"
	"github.com/ying32/govcl/vcl/types"
	"github.com/ying32/govcl/vcl/types/colors"
)

func main() {
	vcl.Application.Initialize()

	mainForm := vcl.Application.CreateForm()
	mainForm.SetPosition(types.PoScreenCenter)
	mainForm.SetWidth(500)
	mainForm.SetHeight(400)

	lv1 := vcl.NewListView(mainForm)
	lv1.SetParent(mainForm)
	lv1.SetAlign(types.AlTop)
	lv1.SetRowSelect(true)
	lv1.SetReadOnly(true)
	lv1.SetViewStyle(types.VsReport)
	lv1.SetGridLines(true)

	col := lv1.Columns().Add()
	col.SetCaption("序号")
	col.SetWidth(100)

	col = lv1.Columns().Add()
	col.SetCaption("项目1")
	col.SetWidth(200)

	lv1.Items().BeginUpdate()
	for i := 1; i <= 20; i++ {
		item := lv1.Items().Add()
		item.SetCaption(fmt.Sprintf("%d", i+rand.Int()))
		item.SubItems().Add(fmt.Sprintf("值:%d", i+rand.Int()))
	}
	lv1.Items().EndUpdate()

	lv1.SetOnAdvancedCustomDrawItem(ListViewAdvancedCustomDrawItem)
	lv1.SetOnAdvancedCustomDrawSubItem(lvTraiAdvancedCustomDrawSubItem)

	vcl.Application.Run()
}

func lvTraiAdvancedCustomDrawSubItem(sender *vcl.TListView, item *vcl.TListItem, subItem int32,
	state types.TCustomDrawState, stage types.TCustomDrawStage, defaultDraw *bool) {
	canvas := sender.Canvas()

	switch subItem {
	case 0:
		canvas.Brush().SetColor(0x02E0F0F7)
	default:
		canvas.Brush().SetColor(0x02F0EEF7)
	}
}

func ListViewAdvancedCustomDrawItem(sender *vcl.TListView, item *vcl.TListItem, state types.TCustomDrawState, Stage types.TCustomDrawStage, defaultDraw *bool) {

	sender.Canvas().Brush().SetColor(colors.ClRed)
}

微信截图_20190428112802

from govcl.

ismlsmile avatar ismlsmile commented on May 17, 2024

前面我就是这么弄的:),就是感觉有点啰嗦,要写两个方法,如果没有其它更好的办法,就先这么弄吧,多谢了。

from govcl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.