How do i set Border properties on a TextBox Control in Winforms so that It displays sunken borders?
Any ideas?
Thanks
Unusual request. But you can do it by selectively disable the theming for the control. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
using System;
using System.Windows.Forms;
class SunkenTextBox : TextBox {
protected override void CreateHandle() {
base.CreateHandle();
SetWindowTheme(this.Handle, "", "");
}
[System.Runtime.InteropServices.DllImport("uxtheme.dll")]
private static extern void SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}
Just add the Microsoft Forms textbox Control to your toolbox.
alt text http://img262.imageshack.us/img262/2989/28550946.png
You need to remove the Application.EnableVisualStyles() call from your Program.cs file.
Related
I want to customize normal WPF Ribbon layout.
As shown below I want to remove the command area of ribbon control.
Please suggest any way to achieve this.
I got the solution from this link
void ribbon_Loaded(object sender, RoutedEventArgs e)
{
Grid child = VisualTreeHelper.GetChild((DependencyObject)sender, 0) as Grid;
if (child != null)
{
child.RowDefinitions[0].Height = new GridLength(0);
}
}
If you want to move the Quick Access Toolbar spacing you can change the main window to be a RibbonWindow. This will move the Quick Access Toolbar to the top title bar. If there are no items, it will be hidden.
XAML:
<ribbon1:RibbonWindow x:Class="Example.MainWindow"
xmlns:ribbon1="clr-namespace:System.Windows.Controls.Ribbon;
assembly=System.Windows.Controls.Ribbon"
...
Codebehind:
namespace Example
{
public partial class MainWindow : RibbonWindow
{
...
I am making a Excel Addin in VS2010.
The following code work fines if I make a winforms usercontrol
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var testControlView1 = new UserControl1();
var MyCustomPane = this.CustomTaskPanes.Add(testControlView, "Hello");
}
However I would like to make my UserControl1 be a WPF UserControl. Does anybody know how I would achieve similar functionality or an alternate approach?
As far as I can tell the CustomTaskPanes only allows Winforms Controls to be added to it.
Answer summary:
1. Add a .net winforms usercontrol
2. Add a SWF.Integration.ElementHost control to the user control.
3. Add a Wpf control to your project seperately (not to the user control).
3. Use the Hosted Content property (hostedcontentName) of the ElementHost control and set it to the wpf control.
I found this blog post that answered it great...
I have a custom control which is dynamically adding a number of checkboxes. I can't figure out how to apply a default style to them from code in the custom control (from the generic.xaml file)
I am having a shot in the dark here, but do you have a default "theme" file that you want to apply to dynamically added UIelements in some custom UserControl?
if so,
Try something like:
public Page()
{
InitializeComponent();
Uri uri = new Uri(#"QuoteInterface;component/Theme/WhistlerBlue.xaml", UriKind.Relative);
ImplicitStyleManager.SetResourceDictionaryUri(LayoutRoot, uri);
ImplicitStyleManager.SetApplyMode(LayoutRoot, ImplicitStylesApplyMode.Auto);
ImplicitStyleManager.Apply(LayoutRoot);
}
That seems to work for me, even when I add dynamically generated user controls
I have a strange bug with WPF Interop and an Excel Addin. I'm using .Net 3.5 SP1.
I'm using Add-in Express to create a Custom Task Pane for Excel 2003. Within that taskpane I'm using ElementHost to host a WPF UserControl. The UserControl simply contains a Grid with a TextBox and ComboBox. My problem is that whilst everything displays properly, the ComboBox won't stay dropped-down unless I hold the mouse down over the down-arrow.
I don't believe this is necessarily related to Add-in Express because I've had a similar problem when I tried displaying a WPF window modelessly in Excel.
A second problem is that the ComboBox seems reluctant to give up focus. If I click it, the text area goes grey to indicate that it has focus, but I can't move focus anywhere else in the window. The only way to wrest focus away is to move the mousewheel.
Anybody else had a similar problem, and managed to fix it?
Add-in Express looked into this for me, and it turns out to have something to do with the Window style of the Task Pane that gets added to Excel. If you turn off the WS_CHILD flag in the Windows CreateParams then Combo Boxes and other popups work as expected.
They gave me this snippet of code to add to my ADXExcelTaskPane:
private const uint WS_CHILD = 0x40000000;
private const uint WS_CLIPCHILDREN = 0x02000000;
private const uint WS_CLIPSIBLINGS = 0x04000000;
private CreateParams _CreateParams = new CreateParams();
protected override CreateParams CreateParams
{
get
{
_CreateParams = base.CreateParams;
if (!DesignMode)
_CreateParams.Style = (int)(WS_CLIPCHILDREN | WS_CLIPSIBLINGS); //| WS_CHILD
return _CreateParams;
}
}
I had the same problem. I have a WPF user control hosted in a WinForm user control and the whole is an Excel AddIn. I work with Visual Studio 2010 and Excel 2007 and Excel 2010.
My problem was that when I clicked once in the Excel sheet, the AddIn never gains focus again.
I found a workaround.
In the constructor of my WinForm user control, I register on the event MouseEnter of my WPF user control.
In the MouseEnter event handler, I give the focus to myself (this.Focus())
public WpfContainerUserControl()
{
InitializeComponent();
GpecsBrowserTabUserControl gpecBrowser = elementHost1.Child as GpecsBrowserTabUserControl;
gpecBrowser.MouseEnter += new System.Windows.Input.MouseEventHandler(gpecBrowser_MouseEnter);
}
void gpecBrowser_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
this.Focus();
}
How can I go about hosting flash content inside a WPF form and still use transparency/alpha on my WPF window? Hosting a WinForms flash controls does not allow this.
Unless the control you use to display the Flash content is built in WPF, you will run in to these "airspace" issues. Every display technology from Win32 to WinForms used HWNDs "under the hood", but WPF uses DirectX. The Window Manager in Windows however, still only understands HWNDs, so WPF apps have one top-level HWND-based window, and everything under that is done in DirectX (actually things like context menus and tooltips also have top-level HWNDs as well). Adam Nathan has a very good description of WPF interop in this article.
Although I haven't done it, you can probably use the WebBrowser control found in WPF 3.5 sp1 to wrap your Flash content within WPF. I'm not sure how the transparency will be affected though.
Can you use Expression to convert the flash content to XAML? I believe that there are tools in there or off to the side that do this.
Just have been struggling with same problem of how to upload & Make WPF transparent with ability of displaying Flash, because if you enable on your MainWindow "Allow transparency" Flash will not show once the application will run.
1) I used WebBrowser Control to play Flash(.swf) files. They are on my PC, however it can play from internet or wherever you have hosted them. Don't forget to name your WebBrowser Control to get to it in C#.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MyHelper.ExtendFrame(this, new Thickness(-1));
this.MyBrowser.Navigate(#"C:\Happy\Download\flash\PlayWithMEGame.swf");
}
2) Now for transparency. I have set in WPF 'false' to "Allow Transparency" and set "Window Style" to 'None'. After that I have used information from HERE and HERE and created a following code that produced desired effect of allowing transparency on MainWindow and running Flash at same time, here is my code:
public class MyHelper
{
public static bool ExtendFrame(Window window, Thickness margin)
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
MARGINS margins = new MARGINS(margin);
DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
}
struct MARGINS
{
public MARGINS(Thickness t)
{
Left = (int)t.Left;
Right = (int)t.Right;
Top = (int)t.Top;
Bottom = (int)t.Bottom;
}
public int Left;
public int Right;
public int Top;
public int Bottom;
}
And called it from Window_Loaded() + you need 'below' line for 'DllImport' to work.
using System.Runtime.InteropServices;
using System.Windows.Interop;