将c#windows面板转换为c HWND(Convert c# windows panel to c HWND)
我有一个接受HWND的dll,(dll中的代码);
void VideoCapture::SetVideoWindow(HWND VidWind) { VideoWindow = VidWind; }
我在c#.net应用程序中调用了上面的dll,在c#.net中添加了dll,我有一个带有Panel的表单,是否可以将该面板传递给dll? 我在c#中给出了如下代码
VidCapWrapper.ManagedVideoCapture cc = new VidCapWrapper.ManagedVideoCapture(); cc.SetVideoWindow( panel1);
我得到的错误如下:'错误2'VidCapWrapper.ManagedVideoCapture.SetVideoWindow(HWND__ )'的最佳重载方法匹配有一些无效的参数D:\ DirectShow_Capture_GUI \ DirectShow_Capture_GUI \ Form1.cs 44 13 DirectShow_Capture_GUI错误3参数1:无法转换从'System.Windows.Forms.Panel'到'HWND__ 'D:\ DirectShow_Capture_GUI \ DirectShow_Capture_GUI \ Form1.cs 44 32 DirectShow_Capture_GUI`
任何人都可以告诉我如何将面板传递给dll,(任何一个例子都会很好)? (抱歉,我对.net很新,但尝试创建一个示例应用程序,显示集成网络摄像头等可用设备...然后在c#.net表单面板上显示预览)
编辑 :感谢@Blachshma和@Hans Passant,现在我能够将c#windows窗体的面板传递给我的c ++ dll。
我在dll中改变了我的功能
void VideoCapture::SetVideoWindow(IntPtr windowHandle) { VideoWindow = (HWND)windowHandle.ToPointer(); }
在c#我称之为cc.SetVideoWindow(panel1.Handle);
I have a dll which accepts HWND, (code in the dll);
void VideoCapture::SetVideoWindow(HWND VidWind) { VideoWindow = VidWind; }
i am calling the above dll in a sample c#.net application by adding the dll in references, in c#.net i have a form with Panel, is it possible to pass that panel to the dll? i gave code as below in c#
VidCapWrapper.ManagedVideoCapture cc = new VidCapWrapper.ManagedVideoCapture(); cc.SetVideoWindow( panel1);
i am getting errors as below: 'Error 2 The best overloaded method match for 'VidCapWrapper.ManagedVideoCapture.SetVideoWindow(HWND__)' has some invalid arguments D:\DirectShow_Capture_GUI\DirectShow_Capture_GUI\Form1.cs 44 13 DirectShow_Capture_GUI Error 3 Argument 1: cannot convert from 'System.Windows.Forms.Panel' to 'HWND__' D:\DirectShow_Capture_GUI\DirectShow_Capture_GUI\Form1.cs 44 32 DirectShow_Capture_GUI`
Can any one please tell me how to pass panel to dll, (any example will be good)? (sorry i am very new to .net, but trying to create a sample app which shows available devices like integrated webcam... and then shows preview on c#.net form panel)
EDIT: Thanks to Both @Blachshma and @Hans Passant, Now i am able to pass c# windows form's panel to my c++ dll.
I changed my func in dll as
void VideoCapture::SetVideoWindow(IntPtr windowHandle) { VideoWindow = (HWND)windowHandle.ToPointer(); }
and in c# i am calling it as cc.SetVideoWindow(panel1.Handle);
原文:https://stackoverflow.com/questions/13821680
最满意答案
添加文本框架文本后,需要设置字体大小。
data_label = p.data_label ... text_frame = data_label.text_frame # text_frame.clear() # this line is not needed, assigning to .text does this text_frame.text = str.format('{0:.1f}', v) for paragraph in text_frame.paragraphs: paragraph.font.size = Pt(10) # -- OR -- for run in text_frame.paragraphs[0].runs: run.font.size = Pt(10)
当您调用
TextFrame.text
,将删除所有现有段落并添加一个新段落。 在此过程中,删除所有字符格式以在添加指定文本之前生成“干净的平板”。我不记得PowerPoint是否尊重段落级别的字体集(使用
a:defRPr
元素)。 如果没有,您需要在运行级别执行此操作,如“ - OR”行后所示。You need to set the font size after adding the text frame text.
data_label = p.data_label ... text_frame = data_label.text_frame # text_frame.clear() # this line is not needed, assigning to .text does this text_frame.text = str.format('{0:.1f}', v) for paragraph in text_frame.paragraphs: paragraph.font.size = Pt(10) # -- OR -- for run in text_frame.paragraphs[0].runs: run.font.size = Pt(10)
When you call
TextFrame.text
, all existing paragraphs are removed and a single new paragraph is added. Along the way, all character formatting is removed to produce a "clean slate" before adding the specified text.I don't recall whether PowerPoint respects the font set at the paragraph level (using the
a:defRPr
element). If not, you'll need to do it at the run level, as shown after the -- OR -- line.
相关问答
更多-
3.4和3.5之间的差异不太可能打破已经能够处理2.7和更低的包,差异不是那么大。 听起来更像是没有为python-pptx所依赖的lxml安装正确的二进制文件。 由于lxml仅作为python 3.2的wheel使用,因此你的pip install会尝试从源代码编译lxml 。 从包含\r\n的消息我假设你使用的是Windows和Python 3.5,在PyPI上没有lxml轮子,所以你应该尝试从Christoph Gohlke的非官方版本中安装lxml ,特别是最后两个中的一个,在名称中有cp35 ,来 ...
-
python pptx获取表格宽度(python pptx get table width)[2024-01-21]
Table中.columns的属性是.columns ,因此: for column in table.columns: yield column.width 文档的API部分提供了每个属性和每个属性的描述,例如,此页面描述了表对象API: http : //python-pptx.readthedocs.io/en/latest/api/table.html The property you want on Table is .columns, so: for column in table.c ... -
它不会像文本一样工作; 图像上没有中心对齐或对齐属性。 你需要使用一个公式。 image.left = (prs.slide_width - image.width) / 2 It's not going to work the same way as text; there's no center justification or alignment property on an image. You'll need to use a formula. image.left = (prs.slide_w ...
-
如何在Python-pptx创建的表中更改文本的字体大小(How to change font size of text within a table created by Python-pptx)[2023-04-16]
_Cell对象不直接包含段落。 但是,它确实包含.text_frame上的.text_frame对象,其中包含段落。 所以如果你只是使用: cell.text_frame.paragraphs[0] ..你应该得到你所期望的。 请注意,它是.paragraphs,而不是.paragraph。 _Cell的API文档位于: http : _Cell 并且通常提供解决像这样的更精细点所需的所有细节。 A _Cell object doesn't directly contain paragraphs. How ... -
Python-PPTX:更改表格样式或向单元格添加边框(Python-PPTX: Changing table style or adding borders to cells)[2022-09-15]
也许不是真正干净的代码,但允许我调整表中所有单元格的所有边框: from pptx.oxml.xmlchemy import OxmlElement def SubElement(parent, tagname, **kwargs): element = OxmlElement(tagname) element.attrib.update(kwargs) parent.append(element) return element def _ ... -
图表中的条形图没有单独的位置和大小信息,至少不存储在.pptx文件的XML中。 所以简短的回答是你不能直接做你要求使用的python-pptx。 例如,使用VBA访问的MS API,以及使用Iron Python的MS API,确实提供了Point.left,.top,.width和.height。 所以,如果你能够忍受艰辛,那么你可以在那个环境中做点什么:)请注意,像这样的代码直接操作PowerPoint应用程序实例,只有在我没有弄错的情况下才能在Windows中操作。 因此,如果您尝试在服务器端运行,那 ...
-
添加文本框架文本后,需要设置字体大小。 data_label = p.data_label ... text_frame = data_label.text_frame # text_frame.clear() # this line is not needed, assigning to .text does this text_frame.text = str.format('{0:.1f}', v) for paragraph in text_frame.paragraphs: paragr ...
-
Python pptx模块(Python pptx module)[2022-04-07]
引自python-ppty开发人员的dev-group - 如果你知道它的索引,就像table = slide.shapes[2]那样可以解决问题。 然后,您需要在更改其内容之前导航单元格: for idx, row in enumerate(table.rows): if idx = 0: # skip header row continue name_cell = row.cells[0] name_cell.text = 'foobar' corner ... -
我不确定Word中的哪些对象可以有边框。 我希望段落可以,但不确定一行文本可以。 您可以通过试用Word UI快速确定这一点。 无论如何,该功能尚未在python-docx实现。 I'm not sure what objects in Word can have a border. I expect a paragraph can, but not sure a run of text can. You can determine this pretty quickly by experimenting ...
-
python pptx将表格拟合到精确大小并自动将文本固定到它(python pptx fit table to exact size and autofix the text to it)[2023-03-04]
我的工作类似于一个类似的要求,这就是我处理一个具有随机可能行数的表的方法。 识别具有最大字符的列。在我的情况下,我只有一列具有不同的内容。 尝试粗略估计一张幻灯片上可容纳的字符数。 如果文本达到最大字符并进入下一张幻灯片,创建表格并填写剩余内容,请提供逻辑来打破文本。 I worked on a similar requirement and this is how I handled a table with random number of possible rows. Identify the col ...