当前位置:首页 » 背景图片 » switch怎么改背景图片
扩展阅读
抱头图片男人 2024-11-16 17:34:26

switch怎么改背景图片

发布时间: 2022-04-24 06:51:42

1. switch怎么开机

  • 1

    首先找到switch主机屏幕上方的电源键按钮并按住。

2. 我有两张Winform主窗体的背景图片,在运行时怎么样切换背景图片,就像换皮肤一样

C#winform中给mdi主窗体添加自定义背景图片2011-07-06 16:05修改MDI窗口的主背景是MS不推荐的,但如果你需要可以使用下面的方法:

1——
原理:
MDI窗口有一个叫MdiClient的窗口对象作为主背景窗口,要修改MDI窗口的背景就是修改该MdiClient对象的背景

2——
关键:
如何获得MdiClient对象

3——
方法:
MdiClient是作为MDI窗口的一个ChildControl的形式存在的,因此我们可以通过遍历MDI窗口的Controls对象集来获得

4——
示例:
下面的代码把MDI窗口的主背景修改为兰色(如果你有特别的处理请作相应的处理)

private System.Windows.Forms.MdiClient m_MdiClient;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
int iCnt=this.Controls.Count;
for(int i=0;i<iCnt;i++)
{
if(this.Controls[i].GetType().ToString()=="System.Windows.Forms.MdiClient")
{
this.m_MdiClient=(System.Windows.Forms.MdiClient)this.Controls[i];
break;
}
}
this.m_MdiClient.BackColor=System.Drawing.Color.Blue;
}

具体的应用中,可以参考上面的代码把背景修改为其他的颜色、用图片平铺、拉伸等,就象通过代码修改非MDI窗口的背景一样。

另外,具体应用时,可能要考虑把这些东西放置到Paint或erasebkground等事件。

c# 2.0 给MDI主窗口添加背景最简单的办法,4句代码搞定

一、将MDI主窗口的IsMdiContainer设为 False,将背景图片放到资源文件中,资源名为BackgroundImage
二、在MDI主窗口的构造函数中InitializeComponent();之后加下面4行代码
MdiClient m = new MdiClient();
this.Controls.Add( m );
m.Dock = DockStyle.Fill;
m.BackgroundImage = Properties.Resources.BackgroundImage ;

using System;
using System.ComponentModel;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace myBackgroundImage
{
/// <summary>
/// fat background MDI form (fbgMDIform),可定制Mdi主窗体背景。
/// </summary>
public class fbgMDIform:System.Windows.Forms.Form
{
private MDIbg_TypeList _mdibg_type;
private Image _mdibg_image;
private Image _mdibg_bgimage;

private MDIbg_AlignList _mdibg_align;
private MDIbg_ValignList _mdibg_valign;

private System.Windows.Forms.MdiClient bgMDIClient;

#region" 公共属性 "

[Browsable(true),Description("背景图片呈现风格:File填充,以截取右上角或重复出现的方式填满整个工作区;Draw 拉伸,一张图片拉伸后布满工作区;Logo标志,一张图片,其他属性控制具体位置。"), Category("MDI背景扩展设置")]
public MDIbg_TypeList MDIbg_Type
{
get
{
object obj=_mdibg_type;
return (obj==null)?MDIbg_TypeList.File:(MDIbg_TypeList)obj;
}
set { _mdibg_type=value; }
}

[Browsable(true),Description("MDIContainer背景图片"),Category("MDI背景扩展设置")]
public Image MDIbg_Image
{
get { return _mdibg_image; }
set { _mdibg_image=value; }
}

[Browsable(true),Description("MDIContainer第二背景图片,MDIbg_Type设置为Logo时,此属性对 应图片以拉伸的形式在MDIbg_Image的下一层布满工作区,若留空则由背景色替代。"), Category("MDI背景扩展设置")]
public Image MDIbg_bgImage
{
get { return _mdibg_bgimage; }
set { _mdibg_bgimage=value; }
}

[Browsable(true),Description("MDIbg_Image的左右对齐方式,取值为Left、Center、Right,MDIbg_Type设置为Logo时有效。"), Category("MDI背景扩展设置")]
public MDIbg_AlignList MDIbg_Align
{
get
{
object obj=_mdibg_align;
return (obj==null)?MDIbg_AlignList.Left:(MDIbg_AlignList)obj;
}
set { _mdibg_align=value; }
}

[Browsable(true),Description("MDIbg_Image的上下对齐方式,取值为Top、Middle、Bottom,MDIbg_Type设置为Logo时有效。"), Category("MDI背景扩展设置")]
public MDIbg_ValignList MDIbg_Valign
{
get
{
object obj=_mdibg_valign;
return (obj==null)?MDIbg_ValignList.Top:(MDIbg_ValignList)obj;
}
set { _mdibg_valign=value; }
}

#endregion

#region" 枚举相关 "

//呈现风格枚举
public enum MDIbg_TypeList:byte
{
File, //File填充,多张图片重复后布满工作区

Draw, //Draw拉伸,一张图片拉伸后布满工作区

Logo //Logo标志,一张图片,其他属性控制具体位置
}

//图片左右对齐方式枚举
public enum MDIbg_AlignList:byte
{
Left, //居左

Center, //居中

Right //居右
}

//图片上下对齐方式枚举
public enum MDIbg_ValignList:byte
{
Top, //居上

Middle, //居中

Bottom //居下

}

#endregion

public fbgMDIform()
{
this.SizeChanged += new System.EventHandler(this.MDI_Set);
this.Load+=new EventHandler(this.MDI_Set);

}

private void MDI_Set(object sender, System.EventArgs e)
{
if(this.IsMdiContainer)
{
foreach(System.Windows.Forms.Control myControl in this.Controls)
{
if(myControl.GetType().ToString() == "System.Windows.Forms.MdiClient")
{
bgMDIClient = (System.Windows.Forms.MdiClient)myControl;
break;
}
}

if(bgMDIClient.ClientSize.Width>0&&bgMDIClient.ClientSize.Height>0&&MDIbg_Image!=null)
{

System.Drawing.Bitmap myImg = new Bitmap(bgMDIClient.ClientSize.Width,bgMDIClient.ClientSize.Height);
System.Drawing.Graphics myGraphics = System.Drawing.Graphics.FromImage(myImg);
myGraphics.Clear(this.BackColor);

switch (this.MDIbg_Type)
{
case MDIbg_TypeList.File:
//填充
myImg = new Bitmap(this.MDIbg_Image);
myGraphics = System.Drawing.Graphics.FromImage(myImg);
myGraphics.Clear(this.BackColor);
myGraphics.DrawImage(this.MDIbg_Image,0,0,myImg.Width+1,myImg.Height+1);
bgMDIClient.BackgroundImage =myImg;
myGraphics.Dispose();
break;
case MDIbg_TypeList.Draw:
//拉伸
myGraphics.DrawImage(this.MDIbg_Image,0,0,myImg.Width+1,myImg.Height+1);
bgMDIClient.BackgroundImage = myImg;
myGraphics.Dispose();
break;
case MDIbg_TypeList.Logo:
//标志
myGraphics.Clear(this.BackColor);

if(this.MDIbg_bgImage!=null)
{
myGraphics.DrawImage(this.MDIbg_bgImage,0,0,myImg.Width+1,myImg.Height+1);
}
//定位
int myX,myY;
switch(this.MDIbg_Align)
{
case MDIbg_AlignList.Left:
myX=0;
break;
case MDIbg_AlignList.Right:
myX=myImg.Width-MDIbg_Image.Width;
break;

case MDIbg_AlignList.Center:
myX=(myImg.Width-MDIbg_Image.Width)/2;
break;
default:
myX=0;
break;
}
switch(this.MDIbg_Valign)
{
case MDIbg_ValignList.Top:
myY=0;
break;
case MDIbg_ValignList.Bottom:
myY=myImg.Height -MDIbg_Image.Height;
break;

case MDIbg_ValignList.Middle:
myY=(myImg.Height -MDIbg_Image.Height)/2;
break;
default:
myY=0;
break;
}
myGraphics.DrawImage(this.MDIbg_Image,myX,myY,this.MDIbg_Image.Width,this.MDIbg_Image.Height);
bgMDIClient.BackgroundImage = myImg;
myGraphics.Dispose();
break;
default:
//填充
bgMDIClient.BackgroundImage =this.MDIbg_Image;
break;
}
}
}
}

}
}
放在类库中编译,然后在程序中引用

3. ios中uiswitch超出的背景颜色怎样处理

1、创建一个empty(空的)工程项目,新建一个UIViewController;
2、选中工程,右键-New File…选择“Cocoa Touch Class”-Next,给个合理的名称ViewController,再Next完成;
3、在AppDelegate.m文件包含#import "ViewController.h";
4、初始化创建ViewController的视图控制器,并用导航栏控制器包含。将之设置为根视图控制器。

创建添加UISwitch对象
1、创建并初始化一个UISwitch,宽高是固定的,不为0就可以显示;
3、设置背景颜色可以看到效果;
4、将UISwitch添加到self.view中。

设置UISwitch的属性
1、onTintColor设置开启颜色;
2、onImage设置开启图片;
3、tintColor设置正常关闭颜色;
4、offImage设置关闭图片;
5、thumbTintColor设置圆形按钮颜色;

代码设置开启/关闭状态

//设置YES或NO,是否使用animated动画效果:
[mySwitch setOn:YES animated:YES];

获取UISwitch的开启/关闭状态

1、获取对象的isOn属性,默认是关闭状态;
2、如果isOn==YES则是开启状态,如果isOn==NO则是关闭状态。

添加动作事件(完成)
可以选择id类也可以选择UISwitch类,如果是id类型,则要转换成UISwitch类型:UISwitch *mySwitch = (UISwitch *)sender。

4. android 自定义switch样式

修改后的MySwitch控件接口基本与原Switch控件一致,并且除了可支持所有SDK外,增加了2项小功能:
1. 支持用Track背景图片的方式代替Texton Textoff等文字方式表现开关状态
2.支持调整控制Switch的高度
下面贴出Switch修改的关键代码:

/**
* <p>
* modified from android SDK 14(4.0) android.widget.Switch.
* <br/>
* <strong>new feature: </strong>
* <ol>
* <li>support SDK 1 or higher. </li>
* <li>you can use track drawable instead of text to display the changes of off-on state!</li>
* <li>you can control the Switch minimum height. </li>
* </ol>
* </p>
*
* @see {@link Switch}
* @author Wison
*/
public class MySwitch extends CompoundButton {
// Support track drawable instead of text
private Drawable mTrackOnDrawable;
private Drawable mTrackOffDrawable;

// Support minimum height
private int mSwitchMinHeight;

/**
* Construct a new Switch with a default style determined by the given theme attribute,
* overriding specific style attributes as requested.
*
* @param context The Context that will determine this widget's theming.
* @param attrs Specification of attributes that should deviate from the default styling.
* @param defStyle An attribute ID within the active theme containing a reference to the
* default style for this widget. e.g. android.R.attr.switchStyle.
*/
public MySwitch(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
Resources res = getResources();
mTextPaint.density = res.getDisplayMetrics().density;
//float scaledDensity = res.getDisplayMetrics().scaledDensity;
//mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyle, 0);

// off-on 模式: 图片模式或文字模式,图片模式是用Track背景图片表示off-on的状态,文字模式是用文字来表示off-on状态。
mTrackOnDrawable = a.getDrawable(R.styleable.Switch_trackOn);
mTrackOffDrawable = a.getDrawable(R.styleable.Switch_trackOff);
if (checkTrackOffOnDrawable()) {
// 如果设定图片模式,则默认显示off状态
mTrackDrawable = mTrackOffDrawable;
} else {
mTrackDrawable = a.getDrawable(R.styleable.Switch_track);
}

mThumbDrawable = a.getDrawable(R.styleable.Switch_thumb);
mTextOn = a.getText(R.styleable.Switch_textOn);
mTextOff = a.getText(R.styleable.Switch_textOff);
mThumbTextPadding = a.getDimensionPixelSize(R.styleable.Switch_thumbTextPadding, 0);
mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.Switch_switchMinWidth, 0);

mSwitchMinHeight = a.getDimensionPixelSize(R.styleable.Switch_switchMinHeight, 0);

mSwitchPadding = a.getDimensionPixelSize(R.styleable.Switch_switchPadding, 0);

int appearance = a.getResourceId(R.styleable.Switch_switchTextAppearance, 0);
if (appearance != 0) {
setSwitchTextAppearance(context, appearance);
}
a.recycle();

ViewConfiguration config = ViewConfiguration.get(context);
mTouchSlop = config.getScaledTouchSlop();
mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

// Refresh display with current params
refreshDrawableState();
setChecked(isChecked());
}

private boolean checkTrackOffOnDrawable() {
return mTrackOnDrawable != null && mTrackOffDrawable != null;
}

@SuppressLint("NewApi")
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mOnLayout == null) {
mOnLayout = makeLayout(mTextOn);
}
if (mOffLayout == null) {
mOffLayout = makeLayout(mTextOff);
}
mTrackDrawable.getPadding(mTempRect);
final int maxTextWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth());
final int switchWidth = Math.max(mSwitchMinWidth,
maxTextWidth * 2 + mThumbTextPadding * 4 + mTempRect.left + mTempRect.right);

// final int switchHeight = mTrackDrawable.getIntrinsicHeight();
int switchHeight;
if (mSwitchMinHeight <= 0) {
switchHeight = mTrackDrawable.getIntrinsicHeight();
} else {
switchHeight = Math.max(mSwitchMinHeight, mTempRect.top + mTempRect.bottom);
}
mThumbWidth = maxTextWidth + mThumbTextPadding * 2;

mSwitchWidth = switchWidth;
mSwitchHeight = switchHeight;

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int measuredHeight = getMeasuredHeight();
if (measuredHeight < switchHeight) {
if (Build.VERSION.SDK_INT >= 11) {
setMeasuredDimension(getMeasuredWidthAndState(), switchHeight);
} else {
setMeasuredDimension(getMeasuredWidth(), switchHeight);
}
}
}
@Override
public void setChecked(boolean checked) {
if (checkTrackOffOnDrawable()) {
mTrackDrawable = checked ? mTrackOnDrawable : mTrackOffDrawable;
refreshDrawableState();
}
super.setChecked(checked);
mThumbPosition = checked ? getThumbScrollRange() : 0;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Draw the switch
int switchLeft = mSwitchLeft;
int switchTop = mSwitchTop;
int switchRight = mSwitchRight;
int switchBottom = mSwitchBottom;

if (checkTrackOffOnDrawable()) {
mTrackDrawable = getTargetCheckedState() ? mTrackOnDrawable : mTrackOffDrawable;
refreshDrawableState();
}

mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
mTrackDrawable.draw(canvas);
canvas.save()
mTrackDrawable.getPadding(mTempRect);
int switchInnerLeft = switchLeft + mTempRect.left;
int switchInnerTop = switchTop + mTempRect.top;
int switchInnerRight = switchRight - mTempRect.right;
int switchInnerBottom = switchBottom - mTempRect.bottom;
canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);

mThumbDrawable.getPadding(mTempRect);
final int thumbPos = (int) (mThumbPosition + 0.5f);
int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;

mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
mThumbDrawable.draw(canvas);

// mTextColors should not be null, but just in case
if (mTextColors != null) {
mTextPaint.setColor(mTextColors.getColorForState(getDrawableState(),
mTextColors.getDefaultColor()));
}
mTextPaint.drawableState = getDrawableState();

Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;

if (switchText != null) {
canvas.translate((thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2,
(switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
switchText.draw(canvas);
}
canvas.restore();
}
}

下面是关键属性声明:
<declare-styleable name="Switch">

<!-- Drawable to use when the switch is in the checked/"on" state. -->
<attr name="trackOn" format="reference" />
<!-- Drawable to use when the switch is in the unchecked/"off" state. -->
<attr name="trackOff" format="reference" />
<!-- Minimum height for the switch component -->
<attr name="switchMinHeight" format="dimension" />

<!-- Drawable to use as the "thumb" that switches back and forth. -->
<attr name="thumb" format="reference" />
<!-- Drawable to use as the "track" that the switch thumb slides within. -->
<attr name="track" format="reference" />
<!-- Text to use when the switch is in the checked/"on" state. -->
<attr name="textOn" format="string" />
<!-- Text to use when the switch is in the unchecked/"off" state. -->
<attr name="textOff" format="string" />
<!-- Amount of padding on either side of text within the switch thumb. -->
<attr name="thumbTextPadding" format="dimension" />
<!-- TextAppearance style for text displayed on the switch thumb. -->
<attr name="switchTextAppearance" format="reference" />
<!-- Minimum width for the switch component -->
<attr name="switchMinWidth" format="dimension" />
<!-- Minimum space between the switch and caption text -->
<attr name="switchPadding" format="dimension" />
</declare-styleable>

5. C#中如何单击按钮变换背景图片

这么多个重复的代码。。
个人建议
1、做个函数,里面禁掉所有panel的visible.
再判断if (comboBox1.Text == "1")就显示panel1
或者换为switch case语句更清楚。

2、更简洁的方式。一个string数组,存好12张图的路径
就用一个panel
再判断if (comboBox1.Text == "1")就显示panel1
或者换为switch case语句更清楚。
就设置panel1.BackgroundImage = Image.FromFile(数组元素)就一切搞掂。

有问题直接找我。

6. 如何修改NSview的背景颜色

最简单的方法:打开图片---选择---色彩范围,点击绿色(可以按住SHIFT键,在绿色上反复点击,直到绿色全部被选中),然后在选区填充白色。选区的精度可以用色彩范围里面的逗容差地来调节

7. java swing换背景图片

//回答完毕,采纳即可

importjava.awt.BorderLayout;
importjava.awt.Graphics;
importjava.awt.Image;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjava.io.IOException;

importjavax.imageio.ImageIO;
importjavax.swing.BorderFactory;
importjavax.swing.JButton;
importjavax.swing.JComboBox;
importjavax.swing.JDialog;
importjavax.swing.JFrame;
importjavax.swing.JPanel;

publicclassBarextendsJPanel
{
=1L;

privateJButtonopen;

privatestaticfinalintW=300;

privatestaticfinalintH=300;

publicBar()
{
super(newBorderLayout());

JPanelpanel=newJPanel();
open=newJButton("打开");
open.addActionListener(newActionListener()
{
@Override
publicvoidactionPerformed(ActionEvente)
{
JDialogdialog=newJDialog();
dialog.setTitle("设置背景图");
dialog.setSize(160,60);
dialog.setModal(true);
dialog.setLocationRelativeTo(Bar.this);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
finalJComboBoxcomboBox=newJComboBox(newString[]{"图片a","图片b"});
dialog.addWindowListener(newWindowAdapter()
{
@Override
publicvoidwindowClosing(WindowEvente)
{
try
{
intindex=comboBox.getSelectedIndex();
switch(index)
{
case0:
img=ImageIO.read(Bar.class.getResource("a.jpg"));
Bar.this.repaint();
break;
case1:
img=ImageIO.read(Bar.class.getResource("layout.png"));
Bar.this.repaint();
break;
default:
break;
}
}
catch(IOExceptione1)
{
e1.printStackTrace();
}
}
});
dialog.add(comboBox);
dialog.setVisible(true);
}
});
panel.add(open);
add(panel,BorderLayout.PAGE_START);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

Imageimg=null;

@Override
publicvoidpaint(Graphicsg)
{
super.paint(g);
g.clearRect(0,0,W,H);
g.drawImage(img,0,0,null);
g.dispose();
}

()
{
JFrameframe=newJFrame("bar");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Barb=newBar();
b.setOpaque(true);
frame.setContentPane(b);
frame.setSize(W,H);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

publicstaticvoidmain(String[]args)
{
javax.swing.SwingUtilities.invokeLater(newRunnable()
{
publicvoidrun()
{
createAndShowGUI();
}
});
}
}


8. 如何将switch更改壁纸

直接右键点击图案上面选项中的设为桌面背景

9. switch怎么设置壁纸

没有壁纸。只有深浅两个颜色的壁纸。
如果你是自制系统可以用自定义的主题

10. 任天堂switch有什么美化桌面的软件吗

任天堂这种模式确实有美化桌面的软件,这种软件确实呃非常好用的,但是,一般人不要不要不学的话,那肯定是这个软件是非常不好做的。