问题描述
如何让文字不断显示在图片上?在Form1中添加了一个picturebox,在里面添加了一张图片,在程序运行过程中,会不断显示很多文本,如何让这些文本都显示在图片上方?而且还需要图片上方的文字加一个上下方向的滚动条,以查看显示的文字。我试过在picturebox上方加一个textbox,可是textbox不知道如何把它的背景色变为透明色,请大家帮帮忙,在线等,马上结贴!
解决方案
解决方案二:
marque
解决方案三:
privatevoidpictureBox1_Paint(objectsender,PaintEventArgse){e.Graphics.DrawString("jinjazz",this.Font,Brushes.Red,newPointF(10,10));}
解决方案四:
这段代码是:有一个菜单file下子菜单为Open和Exit;一个OpenFileDialog1;打开一个txt文档,显示在界面上;可以达到你的要求,显示在背景图片之上,出现滚动条。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Collections;namespaceCapsEditor{publicpartialclassForm1:Form{#regionConstantfieldsprivateconststringstandardTitle="CapsEditor";privateconstuintmargine=10;#endregion#regionMemberfieldsprivateArrayListdocumentLines=newArrayList();privateuintlineHeight;privateSizedocumentSize;privateuintnLines;privateFontmainFont;privateFontemptyDocumentFont;privateBrushmainBrush=Brushes.Blue;privateBrushemptyDocumentBrush=Brushes.Red;privatePointmouseDoubleClickPosition;privateOpenFileDialogfileOpenDialog=newOpenFileDialog();privatebooldocumentHasData=false;#endregionpublicForm1(){InitializeComponent();CreateFonts();fileOpenDialog.FileOk+=newCancelEventHandler(this.OpenFileDialog_FileOk);fileOpenDialog.Filter="Text(*.txt)|*.txt|C#(*.cs)|*.cs";}classTextLineInformation{publicstringText;publicuintWidth;}privatevoidCreateFonts(){mainFont=newFont("Arial",10);lineHeight=(uint)mainFont.Height;emptyDocumentFont=newFont("Verdana",13,FontStyle.Bold);}protectedvoidOpenFileDialog_FileOk(objectSender,CancelEventArgse){this.LoadFile(fileOpenDialog.FileName);}privatevoidmenuFileOpen_Click(objectsender,EventArgse){fileOpenDialog.ShowDialog();}privatevoidmenuExit_Click(objectsender,EventArgse){this.Close();}privatevoidLoadFile(stringFileName){StreamReadersr=newStreamReader(FileName);stringnextLine;documentLines.Clear();nLines=0;TextLineInformationnextLineInfo;while((nextLine=sr.ReadLine())!=null){nextLineInfo=newTextLineInformation();nextLineInfo.Text=nextLine;documentLines.Add(nextLineInfo);++nLines;}sr.Close();documentHasData=(nLines>0)?true:false;CalculateLineWidth();CalculateDocumentSize();this.Text=Form1.standardTitle+""+FileName;this.Invalidate();}privatevoidCalculateLineWidth(){Graphicsdc=this.CreateGraphics();foreach(TextLineInformationnextLineindocumentLines){nextLine.Width=(uint)dc.MeasureString(nextLine.Text,mainFont).Width;}}#regionCalculateDocumentSize函数privatevoidCalculateDocumentSize(){if(!documentHasData){documentSize=newSize(100,200);}else{documentSize.Height=(int)(nLines*lineHeight)+2*(int)margine;uintmaxLineLength=0;foreach(TextLineInformationnextWordindocumentLines){uinttempLineLength=nextWord.Width+2*margine;if(tempLineLength>maxLineLength){maxLineLength=tempLineLength;}documentSize.Width=(int)maxLineLength;}this.AutoScrollMinSize=documentSize;}}#endregion
解决方案五:
接上.....protectedoverridevoidOnPaint(PaintEventArgse){base.OnPaint(e);Graphicsdc=e.Graphics;intscrollPosX=this.AutoScrollPosition.X;intscrollPosY=this.AutoScrollPosition.Y;dc.TranslateTransform(scrollPosX,scrollPosY);if(!documentHasData){dc.DrawString("<Emptydocument>",emptyDocumentFont,emptyDocumentBrush,newPoint(20,20));base.OnPaint(e);return;}//workoutwhichlinesareinclippingrectangleintminLineInClipRegion=WorldYCoordinateToLineIndex(e.ClipRectangle.Top-scrollPosY);if(minLineInClipRegion==-1){minLineInClipRegion=0;}intmaxLineInClipRegion=WorldYCoordinateToLineIndex(e.ClipRectangle.Bottom-scrollPosY);if(maxLineInClipRegion>=this.documentLines.Count||maxLineInClipRegion==-1){maxLineInClipRegion=this.documentLines.Count-1;}TextLineInformationnextLine;for(inti=minLineInClipRegion;i<=maxLineInClipRegion;i++){nextLine=(TextLineInformation)documentLines[i];dc.DrawString(nextLine.Text,mainFont,mainBrush,this.LineIndexToWorldCoordinate(i));}}privateintWorldYCoordinateToLineIndex(inty){if(y<margine)return-1;return(int)((y-margine)/lineHeight);}privatePointLineIndexToWorldCoordinate(intindex){PointTopLeftCorner=newPoint((int)margine,(int)(lineHeight*index+margine));returnTopLeftCorner;}privateintWorldCoordinateToLineIndex(Pointpos){if(!documentHasData){return-1;}if(pos.Y<margine||pos.X<margine){return-1;}intindex=(int)(pos.Y-margine)/(int)this.lineHeight;//checkpositionisn'tbelowdocumentif(index>=documentLines.Count){return-1;}//nowcheckthathorizontalpositioniswithinthislineTextLineInformationtheLine=(TextLineInformation)documentLines[index];if(pos.X>margine+theLine.Width)return-1;//allisOk.Wecanreturnanswerreturnindex;}privatePointLineIndexToPageCoordinate(intindex){returnLineIndexToWorldCoordinate(index)+newSize(AutoScrollPosition);}privateintPageCoordinateToLineIndex(Pointpos){//Godblessyou!returnWorldCoordinateToLineIndex(pos-newSize(AutoScrollPosition));}protectedoverridevoidOnDoubleClick(EventArgse){//base.OnDoubleClick(e);//PointMouseLocation=Control.MousePosition;inti=PageCoordinateToLineIndex(this.mouseDoubleClickPosition);if(i>=0){TextLineInformationlineToBeChanged=(TextLineInformation)documentLines[i];lineToBeChanged.Text=lineToBeChanged.Text.ToUpper();Graphicsdc=this.CreateGraphics();uintnewWidth=(uint)dc.MeasureString(lineToBeChanged.Text,mainFont).Width;if(newWidth>lineToBeChanged.Width){lineToBeChanged.Width=newWidth;}if(newWidth+2*margine>this.documentSize.Width){this.documentSize.Width=(int)newWidth;this.AutoScrollMinSize=this.documentSize;}RectanglechageRectangle=newRectangle(LineIndexToPageCoordinate(i),newSize((int)newWidth,(int)this.lineHeight));this.Invalidate(chageRectangle);}base.OnDoubleClick(e);}protectedoverridevoidOnMouseDown(MouseEventArgse){base.OnMouseDown(e);this.mouseDoubleClickPosition=newPoint(e.X,e.Y);}}}
解决方案六:
帮顶
解决方案七:
不是吧几位,我的意思不是要绘图,绘图没有办法实现滚动条效果吧!添加个textbox不行吗?请高手帮帮忙!
解决方案八:
建立一个表格,将该图片设置为背景
解决方案九:
大炮大苍蝇,居然把GDI搬出来了
解决方案十:
panel设置图片背景,顶部panel背景颜色transparent
解决方案十一:
具体是什么意思详细解释一下
解决方案十二:
具体怎么做?麻烦详细解释一下!谢谢!
解决方案十三:
用层啊。
解决方案十四:
<%@pagelanguage="java"contentType="text/html;charset=utf-8"pageEncoding="utf-8"%><html><head><linkrel="StyleSheet"type="text/css"href="css/bt.css"><scripttype="text/javascript"src="js/msg_ajax.js"></script><title>电影详细信息</title></head><body><spanid="btc"style="position:absolute"></span><formmethod="post"name="viewForm"><tableborder="1"><tr><tdalign="middle"><imgborder="0"src="image/9.jpg"id="img1"onmouseover="getDetail('1')"></td><tdalign="middle"><imgborder="0"src="image/9.jpg"id="img2"onmouseover="getDetail('2')"></td><tdalign="middle"><imgborder="0"src="image/9.jpg"id="img3"onmouseover="getDetail('3')"></td></tr></table></form></body></html>js//vartitle;varbody;functionCreateXmlHttpObject(){varxmlHttp=null;try{//Firefox,Opera8.0+,SafarixmlHttp=newXMLHttpRequest();}catch(e){//InternetExplorertry{xmlHttp=newActiveXObject("Msxml2.XMLHTTP");}catch(e){xmlHttp=newActiveXObject("Microsoft.XMLHTTP");}}returnxmlHttp;}functiongetDetail(id){varxmlHttp=CreateXmlHttpObject();if(xmlHttp==null){alert("AJAX对象创建失败!");return;}varurl="";url="http://localhost:9000/testAjax/doGetMsg.do?method=get&id="+id+"&random="+Math.random();xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){vartemp=xmlHttp.responseText;vardisplay=temp.split(",");title=display[0];body=display[1];enableTooltips(id);}};xmlHttp.open("POST",url,true);xmlHttp.send(null);}functionenableTooltips(id){vare1;if(!document.getElementById||!document.getElementsByTagName){return;}//AddCss();//h=document.createElement("span");//h.id="btc";//h.setAttribute("id","btc");//h.style.position="absolute";//document.getElementsByTagName("body")[0].appendChild(h);e1=document.getElementById("img"+id+"");Prepare(e1);}functionPrepare(el){vartooltip,t,b,s,l;tooltip=CreateEl("span","tooltip");s=CreateEl("span","top");s.appendChild(document.createTextNode(title));tooltip.appendChild(s);b=CreateEl("b","bottom");b.appendChild(document.createTextNode(body));tooltip.appendChild(b);setOpacity(tooltip);el.tooltip=tooltip;el.onmouseover=showTooltip;el.onmouseout=hideTooltip;el.onmousemove=Locate;}functionshowTooltip(e){document.getElementById("btc").appendChild(this.tooltip);Locate(e);}functionhideTooltip(e){vard=document.getElementById("btc");if(d.childNodes.length>0){d.removeChild(d.firstChild);}}functionsetOpacity(el){el.style.filter="alpha(opacity:95)";el.style.KHTMLOpacity="0.95";el.style.MozOpacity="0.95";el.style.opacity="0.95";}functionCreateEl(t,c){varx=document.createElement(t);x.className=c;x.style.display="block";return(x);}functionAddCss(){varl=CreateEl("link");l.setAttribute("type","text/css");l.setAttribute("rel","stylesheet");l.setAttribute("href","css/bt.css");l.setAttribute("media","screen");document.getElementsByTagName("head")[0].appendChild(l);}functionLocate(e){varposx=0,posy=0;if(e==null){e=window.event;}if(e.pageX||e.pageY){posx=e.pageX;posy=e.pageY;}else{if(e.clientX||e.clientY){if(document.documentElement.scrollTop){posx=e.clientX+document.documentElement.scrollLeft;posy=e.clientY+document.documentElement.scrollTop;}else{posx=e.clientX+document.body.scrollLeft;posy=e.clientY+document.body.scrollTop;}}}document.getElementById("btc").style.top=(posy+10)+"px";document.getElementById("btc").style.left=(posx-20)+"px";}修改一下就可以了。
解决方案十五:
不好意思,没注意,我的这个是java的。不过方法类似,希望有帮助
解决方案:
该回复于2008-04-09 18:12:45被版主删除