本文目录
- Java编写一个Applent程序,使用fillRect方法输出不同的颜色
- 如何设置pagecontrol上标签的颜色
- MFC 如何指定一个矩形并填充颜色
- C语言图形编程怎么把图形填充成喜欢的颜色
- java设定背景颜色
- 请问VC++的MFC中怎样实现图形的颜色填充啊
- Delphi中checklistbox怎样设置每行字体背景颜色
Java编写一个Applent程序,使用fillRect方法输出不同的颜色
你刚才那题不用关闭的. 追问就可以了.我是刚才那个回答的. import java.applet.Applet;import java.awt.Button;import java.awt.Color;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Random;public class ColorApplet extends Applet { Button bt1; Color color = new Color(0,0,0); Random ran = new Random(); public void init() { bt1 = new Button("随机改变颜色"); bt1.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { if(e.getSource()==bt1){ color = new Color((int)(ran.nextFloat()*255),(int)(ran.nextFloat()*255),(int)(ran.nextFloat()*255)); repaint(); } } } ); add(bt1); } public void paint(Graphics g){ g.setColor(color); g.fillRect(60, 50, 50, 50); }}
如何设置pagecontrol上标签的颜色
试试这样吧procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);var TmpRect: TRect;begin with PageControl1.Canvas do begin Brush.Color := clBlack; Font.Color := clWhite; FillRect(Rect); TmpRect := Rect; OffsetRect(TmpRect, 0, 3); DrawText(Handle, PChar(PageControl1.Pages.Caption), -1, TmpRect, DT_CENTER or DT_VCENTER); end;end;
MFC 如何指定一个矩形并填充颜色
CRect rt(200,200,500,600); pDC-》FillSolidRect(&rt,RGB(255,0,0));//红色填充
C语言图形编程怎么把图形填充成喜欢的颜色
不清楚........... HDC dc = GetDC(g_hWnd); HBRUSH brush=CreateSolidBrush(RGB(0, 255, 0)); HBRUSH oldbrush=(HBRUSH)SelectObject(dc, brush); RECT rect; rect.left = 10; rect.right = 50; rect.top = 10; rect.bottom = 50; FillRect(dc,▭ , brush); Ellipse(dc, 60, 60, 100, 100); SelectObject(dc, oldbrush); Ellipse(dc, 120, 120, 150, 150);
java设定背景颜色
本来是在drawcomponent这个里边使用setBackground,你想啊drawcomponent是继承JComponent的所以它是一个容器,所以它同样有setBackground这个方法来设置它的背景颜色
但是因为你在设置它本身为一个画布,因为你用了paintComponent(Graphics g)
这个方法,所以setBackground这个方法即使你用了也看不到很大的效果。但是有一种取代的方法就是在paintComponent(Graphics g)方法中首先就用Graphics 所含有的方法g.setColor(Color.black);来设置背景颜色再用g.fillRect(0, 0, this.getWidth(), this.getHeight());来填满整个容器,这就达到了设置背景目的。然后你再g.setColor(其他颜色);来绘制其它图形.
具体代码:(在你以上的代码上修改了点)
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g.setColor(Color.black);//这里设置背景颜色
g.fillRect(0, 0, this.getWidth(), this.getHeight());//这里填充背景颜色
double x=100;
double y=100;
double w=200;
double h=150;
Rectangle2D rect=new Rectangle2D.Double(x,y,w,h);
g2.setPaint(Color.white);//这里是你设置其他笔触颜色
g2.draw(rect);
Ellipse2D ellipse=new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.draw(ellipse);
Point2D p1=new Point2D.Double(x-40,y-30);
Point2D p2=new Point2D.Double(x+w+40,y+h+30);
g2.draw(new Line2D.Double(p1,p2));
double centerx=rect.getCenterX();
double centery=rect.getCenterY();
double radius=150;
Ellipse2D circle=new Ellipse2D.Double();
circle.setFrameFromCenter(centerx,centery,centerx+125,centery+125);
g2.draw(circle);
}
测试结果图
请问VC++的MFC中怎样实现图形的颜色填充啊
CClientDC dc(this);//申明一个CDC对象CBrush m_brush;//申明一个格式刷对象m_brush.CreateSolidBrush(RGB(255,0,0));//设置颜色dc.FillRect(CRect(10,10,30,30),&m_brush);
Delphi中checklistbox怎样设置每行字体背景颜色
每行背景设置不同颜色checklistbox;listbox;//-------------------------------------------------procedureTForm1.CheckListBox1DrawItem(Control:TWinControl;Index:Integer;Rect:TRect;State:TOwnerDrawState);beginwithCheckListBox1dobegincase(IndexMod5)of//设置画布的刷子填充色0:Canvas.Brush.Color:=clRed;1:Canvas.Brush.Color:=clBlue;2:Canvas.Brush.Color:=clWhite;3:Canvas.Brush.Color:=clYellow;4:Canvas.Brush.Color:=clSkyBlue;end;Canvas.FillRect(Rect); //将当前项填充背景色Canvas.TextOut(Rect.Left,Rect.Top,Items);//重画Items的Textend;end;//----------------------------------------------------------每行字体设置不同颜色checklistbox;listbox;//----------------------------------------------------------